fix(rules): handle empty matcher as unconditional rule

The matcherSignature function now treats empty strings as unconditional rules
that match any request,
returning "(any)" as the signature instead of
rejecting them.

This enables proper dead code detection when an unconditional
terminating rule shadows later rules.

Adds test coverage for detecting dead rules caused by unconditional
terminating rules.
This commit is contained in:
yusing
2026-02-24 01:42:40 +08:00
parent a94442b001
commit 3c5c3ecac2
2 changed files with 14 additions and 1 deletions

View File

@@ -155,7 +155,7 @@ func ruleOnAlwaysTrue(on RuleOn) bool {
func matcherSignature(raw string) (string, bool) {
raw = strings.TrimSpace(raw)
if raw == "" {
return "", false
return "(any)", true // unconditional rule
}
andParts := splitAnd(raw)

View File

@@ -124,6 +124,19 @@ header Host example.com {
`,
want: nil,
},
{
name: "unconditional terminating rule shadows later unconditional rule",
rules: `
{
error 404 "not found"
}
{
error 403 "forbidden"
}
`,
want: ErrDeadRule,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {