package service import ( "net/http" "net/http/httptest" "testing" "github.com/gin-gonic/gin" "github.com/stretchr/testify/require" ) func TestSanitizedUpstreamPathSuffixRejectsNonConformingSegments(t *testing.T) { // 到达业务代码的 URL.Path 已是百分号解码后的结果,因此用例按解码后的形态书写。 rejected := []string{ "/..", "/../..", "/../../x/y", "/./compact", "/compact/..", `/..\..\x`, `/compact\..`, "/?a=b", "/compact?a=b", "/compact#frag", "/compact%2f..", "/100%", "//double", "/compact//detail", "/compact/", "/ compact", "/compact\x00", "/compact\nX-Injected: 1", "/模型", "compact", "/a:b", "/a;b", "/a,b", "/a=b", "/a&b", // 允许清单是闭集:`\w` + `-` + `.` 以外的字符一律拒绝, // 不依赖任何"已知坏字符"清单。 "/a~b", "/a@b", "/a+b", "/a|b", "/a*b", "/a$b", "/a(b)", "/a'b", "/a\"b", "/a