{"record":{"id":"7fe64f7d42afb1e1","repo":"JuliusBrussee/caveman","slug":"w-rule-q-has-an-empty-pattern","errorCode":null,"errorMessage":"%w: rule %q has an empty pattern","messagePattern":"%w: rule %q has an empty pattern","errorType":"validation","errorClass":"ErrInvalidRule","httpStatus":null,"severity":"error","filePath":"shared/platform/redact/payload.go","lineNumber":582,"sourceCode":"\t\tsb.WriteByte('\\x1e')\n\n\t\tswitch r.Type {\n\t\tcase RuleTypeBuiltin:\n\t\t\t// A reference to the unconditional floor. Nothing to run, and\n\t\t\t// nothing it could switch off.\n\t\t\tcontinue\n\t\tcase RuleTypeRegex:\n\t\tcase RuleTypeJSONPath, RuleTypeHeader:\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: %q (rule %q)\", ErrRuleUnsupported, r.Type, r.Name)\n\t\tdefault:\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: %q (rule %q)\", ErrRuleUnsupported, r.Type, r.Name)\n\t\t}\n\n\t\tif strings.TrimSpace(r.Name) == \"\" {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: empty name\", ErrInvalidRule)\n\t\t}\n\t\tif r.Pattern == \"\" {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q has an empty pattern\", ErrInvalidRule, r.Name)\n\t\t}\n\t\tre, err := regexp.Compile(r.Pattern)\n\t\tif err != nil {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q: %s\", ErrInvalidRule, r.Name, err)\n\t\t}\n\t\tif re.MatchString(\"\") {\n\t\t\t// Such a pattern matches at every position and would replace the\n\t\t\t// whole body with placeholders. Refuse it rather than destroy the\n\t\t\t// capture.\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q matches the empty string\", ErrInvalidRule, r.Name)\n\t\t}\n\t\trepl := r.Replacement\n\t\tif repl == \"\" {\n\t\t\trepl = \"[REDACTED:\" + r.Name + \"]\"\n\t\t}\n\t\tout = append(out, compiledRule{\n\t\t\tname:                 r.Name,\n\t\t\torigin:               OriginOrg,","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/redact/payload.go#L564-L600","documentation":"A regex rule with an empty Pattern is rejected with ErrInvalidRule because there is nothing to match. The pattern is required for RuleTypeRegex rules; the rule name is included in the message for easy location.","triggerScenarios":"Passing a Rule with Type RuleTypeRegex and Pattern \"\" to redact.Payload; rules decoded from config where the pattern key was omitted or set to an empty string.","commonSituations":"Rule authoring UIs/exporters emitting placeholder entries; deleting a pattern from a rule file intending to disable the rule instead of removing it entirely.","solutions":["Supply a valid regex in Pattern, or remove the rule entirely instead of leaving it empty.","Pre-validate r.Pattern != \"\" for regex rules before calling Payload.","If a rule should be temporarily disabled, filter it out of the slice rather than blanking its pattern."],"exampleFix":"// before\nrules := []redact.Rule{{Name: \"cards\", Type: redact.RuleTypeRegex, Pattern: \"\"}}\n// after\nrules := []redact.Rule{{Name: \"cards\", Type: redact.RuleTypeRegex, Pattern: \"\\\\b(?:\\\\d[ -]*?){13,16}\\\\b\"}}","handlingStrategy":"validation","validationCode":"for _, r := range rules {\n    if r.Type == redact.RuleTypeRegex && r.Pattern == \"\" {\n        return fmt.Errorf(\"rule %q has empty pattern\", r.Name)\n    }\n}","typeGuard":null,"tryCatchPattern":"_, _, err := redact.Payload(body, rules)\nif errors.Is(err, redact.ErrInvalidRule) {\n    // fix or drop the empty rule before retrying\n}","preventionTips":["Remove disabled rules entirely rather than blanking patterns","Validate rules at config load time","Make pattern a required field in rule authoring tooling"],"tags":["redaction","invalid-rule","regex"],"backgroundTag":"empty-required-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}