{"record":{"id":"b7a79438d667cc72","repo":"caddyserver/caddy","slug":"replacement-for-query-field-s-v","errorCode":null,"errorMessage":"replacement for query field '%s': %v","messagePattern":"replacement for query field '(.+?)': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/rewrite/rewrite.go","lineNumber":555,"sourceCode":"\tSet []queryOpsArguments `json:\"set,omitempty\"`\n\n\t// Adds query parameters; does not overwrite an existing query field,\n\t// and only appends an additional value for that key if any already exist.\n\tAdd []queryOpsArguments `json:\"add,omitempty\"`\n\n\t// Replaces query parameters.\n\tReplace []*queryOpsReplacement `json:\"replace,omitempty\"`\n\n\t// Deletes a given query key by name.\n\tDelete []string `json:\"delete,omitempty\"`\n}\n\n// Provision compiles the query replace operation regex.\nfunc (replacement *queryOpsReplacement) Provision(_ caddy.Context) error {\n\tif replacement.SearchRegexp != \"\" {\n\t\tre, err := regexp.Compile(replacement.SearchRegexp)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"replacement for query field '%s': %v\", replacement.Key, err)\n\t\t}\n\t\treplacement.re = re\n\t}\n\treturn nil\n}\n\nfunc (q *queryOps) do(r *http.Request, repl *caddy.Replacer) {\n\tquery := r.URL.Query()\n\tfor _, renameParam := range q.Rename {\n\t\tkey := repl.ReplaceAll(renameParam.Key, \"\")\n\t\tval := repl.ReplaceAll(renameParam.Val, \"\")\n\t\tif key == \"\" || val == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tif key == val {\n\t\t\tcontinue\n\t\t}\n\t\toriginalValues, ok := query[key]","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/rewrite/rewrite.go#L537-L573","documentation":"Raised by queryOpsReplacement.Provision when the search_regexp for a query replace operation fails to compile; the message names the query field ('key') whose regex is invalid. It is the inner error that 522 wraps. Compilation uses Go's regexp (RE2), so PCRE-only syntax is unsupported.","triggerScenarios":"rewrite -> query -> replace entry with search_regexp such as \"a{1,\" (bad quantifier) or \"\\\" (trailing backslash).","commonSituations":"Rewriting query parameters (e.g. stripping tracking params) with a hand-written regex that has a typo or unsupported construct.","solutions":["Check the 'key' named in the error and inspect its search_regexp","Fix the RE2 syntax error shown in the wrapped error text","If no regex is needed, clear search_regexp and use search_replace string matching instead","Validate the config before deploy"],"exampleFix":"// before\n{ \"key\": \"utm_source\", \"search_regexp\": \"(?!google)\", \"replace\": \"x\" }\n\n// after (no lookahead in RE2)\n{ \"key\": \"utm_source\", \"search_regexp\": \"^google\", \"replace\": \"x\" }","handlingStrategy":"validation","validationCode":"func validQueryRegex(key, pattern string) error {\n    if pattern == \"\" {\n        return nil\n    }\n    _, err := regexp.Compile(pattern)\n    if err != nil {\n        return fmt.Errorf(\"query field %s: %w\", key, err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote regexes in JSON so backslashes survive","Use regexp.Compile in a unit test for every config constant you embed"],"tags":["caddy","regex","query-string","rewrite"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}