mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-05-31 10:14:15 +00:00
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.
32 lines
537 B
Go
32 lines
537 B
Go
package entity
|
|
|
|
import "testing"
|
|
|
|
func TestPathHasForbiddenChar(t *testing.T) {
|
|
valid := []string{
|
|
"",
|
|
"/",
|
|
"/sub/",
|
|
"/json/",
|
|
"/a/b/c/",
|
|
"/My-Path_123/",
|
|
}
|
|
for _, p := range valid {
|
|
if pathHasForbiddenChar(p) {
|
|
t.Errorf("pathHasForbiddenChar(%q) = true, want false", p)
|
|
}
|
|
}
|
|
|
|
invalid := []string{
|
|
"/sub path/",
|
|
"/back\\slash/",
|
|
"/tab\there/",
|
|
"/new\nline/",
|
|
"/\x7f/",
|
|
}
|
|
for _, p := range invalid {
|
|
if !pathHasForbiddenChar(p) {
|
|
t.Errorf("pathHasForbiddenChar(%q) = false, want true", p)
|
|
}
|
|
}
|
|
}
|