{"record":{"id":"b854f638d6fbf45d","repo":"kataras/iris","slug":"s-w-b854f6","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"validation","errorClass":"ErrParamNotAlphabetical","httpStatus":null,"severity":"warning","filePath":"macro/macros.go","lineNumber":385,"sourceCode":"\t// or \"0\" or \"f\" or \"F\" or \"FALSE\" or \"false\" or \"False\".\n\tBool = NewMacro(\"bool\", \"boolean\", false, false, false, func(paramValue string) (any, bool) {\n\t\t// a simple if statement is faster than regex ^(true|false|True|False|t|0|f|FALSE|TRUE)$\n\t\t// in this case.\n\t\tv, err := strconv.ParseBool(paramValue)\n\t\tif err != nil {\n\t\t\treturn err, false\n\t\t}\n\t\treturn v, true\n\t})\n\n\t// ErrParamNotAlphabetical is fired when the parameter value is not an alphabetical text.\n\tErrParamNotAlphabetical = errors.New(\"parameter is not alphabetical\")\n\talphabeticalEval        = MustRegexp(\"^[a-zA-Z ]+$\")\n\t// Alphabetical letter type\n\t// letters only (upper or lowercase)\n\tAlphabetical = NewMacro(\"alphabetical\", \"\", \"\", false, false, func(paramValue string) (any, bool) {\n\t\tif !alphabeticalEval(paramValue) {\n\t\t\treturn fmt.Errorf(\"%s: %w\", paramValue, ErrParamNotAlphabetical), false\n\t\t}\n\t\treturn paramValue, true\n\t})\n\n\t// ErrParamNotFile is fired when the parameter value is not a form of a file.\n\tErrParamNotFile = errors.New(\"parameter is not a file\")\n\tfileEval        = MustRegexp(\"^[a-zA-Z0-9_.-]*$\")\n\t// File type\n\t// letters (upper or lowercase)\n\t// numbers (0-9)\n\t// underscore (_)\n\t// dash (-)\n\t// point (.)\n\t// no spaces! or other character\n\tFile = NewMacro(\"file\", \"\", \"\", false, false, func(paramValue string) (any, bool) {\n\t\tif !fileEval(paramValue) {\n\t\t\treturn fmt.Errorf(\"%s: %w\", paramValue, ErrParamNotFile), false\n\t\t}","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/macro/macros.go#L367-L403","documentation":"The 'alphabetical' macro fails a route parameter that does not match ^[a-zA-Z ]+$, returning '<value>: parameter is not alphabetical' (wrapping ErrParamNotAlphabetical). This surfaces as a 404-style param-type mismatch at request time (or as the macro error when params are evaluated manually).","triggerScenarios":"A request to a route like /hello/{name:alphabetical} where the segment contains digits, dashes, underscores, or other non-letter/space characters, e.g. /hello/john-doe or /hello/user123.","commonSituations":"URLs containing hyphenated names, slugs, numeric suffixes, or URL-encoded characters; users typing IDs where the route only allows letters and spaces.","solutions":["Relax the param type to {param:string} if any text should be accepted.","Keep alphabetical but validate input in the handler and return a helpful 400 for invalid values.","Add an alternative route with a wider macro (e.g. {name:string regexp(^[a-zA-Z-]+$)}) if dashes must be allowed.","Sanitize/normalize input values client-side to letters-only where applicable."],"exampleFix":"// before\napp.Get(\"/hello/{name:alphabetical}\", h) // rejects \"john-doe\"\n// after\napp.Get(\"/hello/{name:string regexp(^[a-zA-Z- ]+$)}\", h)","handlingStrategy":"validation","validationCode":"var alphabeticalRe = regexp.MustCompile(`^[a-zA-Z ]+$`)\nfunc isAlphabetical(s string) bool { return alphabeticalRe.MatchString(s) }\n// client/handler pre-check before relying on the route\nif !isAlphabetical(param) { /* return 400 or redirect */ }","typeGuard":"func isAlphabeticalParam(v string) bool {\n    for _, r := range v {\n        if !(r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r == ' ') { return false }\n    }\n    return len(v) > 0\n}","tryCatchPattern":"// at request time the router returns 404 for mismatched macros; handle it:\napp.OnErrorCode(iris.StatusNotFound, func(ctx iris.Context) {\n    p := ctx.Path()\n    if strings.Contains(p, \"/hello/\") {\n        ctx.JSON(iris.Map{\"error\": \"name must contain letters and spaces only\"})\n        return\n    }\n    ctx.JSON(iris.Map{\"error\": \"not found\"})\n})","preventionTips":["Document the accepted charset for each param type in route comments.","Normalize/sanitize user input client-side before building URLs.","Prefer explicit {param:string regexp(...)} over built-ins when you need a custom charset.","Return friendly 400s from a global 404 handler when macro mismatches are likely."],"tags":["go","iris","macro","route-parameters","validation"],"backgroundTag":"route-param-type-mismatch","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}