{"record":{"id":"3119e39bb0f1c673","repo":"kataras/iris","slug":"redirect-match-status-code-digits-s-v","errorCode":null,"errorMessage":"redirect match: status code digits: %s: %v","messagePattern":"redirect match: status code digits: (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/rewrite/rewrite.go","lineNumber":299,"sourceCode":"func parseRedirectMatchLine(s string) (*redirectMatch, error) {\n\tparts := strings.Split(strings.TrimSpace(s), \" \")\n\tif len(parts) != 3 {\n\t\treturn nil, fmt.Errorf(\"redirect match: invalid line: %s\", s)\n\t}\n\n\tcodeStr, pattern, target := parts[0], parts[1], parts[2]\n\n\tfor i, ch := range codeStr {\n\t\tif !isDigit(ch) {\n\t\t\treturn nil, fmt.Errorf(\"redirect match: status code digits: %s [%d:%c]\", codeStr, i, ch)\n\t\t}\n\t}\n\n\tcode, err := strconv.Atoi(codeStr)\n\tif err != nil {\n\t\t// this should not happen, we check abt digit\n\t\t// and correctly position the error too but handle it.\n\t\treturn nil, fmt.Errorf(\"redirect match: status code digits: %s: %v\", codeStr, err)\n\t}\n\n\tregex := regexp.MustCompile(pattern)\n\tif regex.MatchString(target) {\n\t\treturn nil, fmt.Errorf(\"redirect match: loop detected: pattern: %s vs target: %s\", pattern, target)\n\t}\n\n\tv := &redirectMatch{\n\t\tcode:              code,\n\t\tpattern:           regex,\n\t\ttarget:            target,\n\t\tnoRedirect:        code <= 0,\n\t\tisRelativePattern: pattern[0] == '/', // search by path.\n\t}\n\n\treturn v, nil\n}\n","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/rewrite/rewrite.go#L281-L317","documentation":"After confirming the code field is all digits, parseRedirectMatchLine still calls strconv.Atoi as a defensive second check. If Atoi fails (e.g. the digits overflow int), the parse fails with this error wrapping the strconv error. It is the fallback arm of the digit validation and rarely fires because the digit loop already ran.","triggerScenarios":"A redirect line whose code field is all digits but not convertible by strconv.Atoi — practically only a numeric string exceeding platform int range (e.g. '99999999999999999999 /old /new').","commonSituations":"Pasting a very long numeric field into the code position, or machine-generated configs with corrupted numeric fields.","solutions":["Shorten the code field to a valid HTTP status code (100–599).","Ensure the code field is the actual status code, not a timestamp or ID accidentally placed first.","Keep the line format strictly 'CODE PATTERN TARGET' so digits land in the right slot."],"exampleFix":"// before\nrewrite.New([]rewrite.RedirectMatchLine{\"99999999999999999999 /old /new\"})\n// after\nrewrite.New([]rewrite.RedirectMatchLine{\"302 /old /new\"})","handlingStrategy":"validation","validationCode":"code, err := strconv.Atoi(strings.Fields(line)[0])\nif err != nil || code < 100 || code > 599 {\n    return fmt.Errorf(\"invalid status code in redirect line %q\", line)\n}","typeGuard":null,"tryCatchPattern":"if _, err := rewrite.New(lines); err != nil {\n    log.Fatalf(\"redirect line rejected: %v\", err) // includes strconv detail\n}","preventionTips":["Restrict code fields to real HTTP status codes (100–599).","Never paste long numeric IDs into the code position.","Validate configs with strconv.Atoi in a pre-flight test."],"tags":["config","rewrite","parsing"],"backgroundTag":"invalid-status-code","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}