mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-09 12:50:59 +00:00
a08bb91f58
webBasePath, subPath, subJsonPath and subClashPath are URL paths, so '/' stays allowed, but spaces, backslashes and control characters break routing. Strip them as you type (shared sanitizePath helper, now also applied to the panel base path) and reject them on save in AllSetting.CheckValid so direct API callers are covered too.
18 lines
484 B
TypeScript
18 lines
484 B
TypeScript
export function sanitizePath(input: string): string {
|
|
let out = '';
|
|
for (const ch of String(input ?? '')) {
|
|
const code = ch.charCodeAt(0);
|
|
if (ch === ':' || ch === '*' || ch === ' ' || ch === '\\' || code < 0x20 || code === 0x7f) continue;
|
|
out += ch;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export function normalizePath(input: string): string {
|
|
let p = input || '/';
|
|
if (!p.startsWith('/')) p = '/' + p;
|
|
if (!p.endsWith('/')) p += '/';
|
|
p = p.replace(/\/+/g, '/');
|
|
return p;
|
|
}
|