{"record":{"id":"a9f911de71fc135f","repo":"kataras/iris","slug":"parameter-is-not-a-file","errorCode":null,"errorMessage":"parameter is not a file","messagePattern":"parameter is not a file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"macro/macros.go","lineNumber":391,"sourceCode":"\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}\n\t\treturn paramValue, true\n\t})\n\t// Path type\n\t// anything, should be the last part\n\t//\n\t// It allows everything, we have String and Path as different","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/macro/macros.go#L373-L409","documentation":"ErrParamNotFile is fired when a parameter evaluated by the 'file' macro contains characters outside letters, digits, underscore, dash, dot (regexp ^[a-zA-Z0-9_.-]*$). It signals that the path segment does not look like a valid filename and is wrapped with the failing value.","triggerScenarios":"Route such as app.HandleDir with a {file:file} path parameter, or any route using {p:file}, and the request segment contains slashes, spaces, or other special characters, e.g. '/files/my file.txt' or '/files/a/b'.","commonSituations":"Users requesting files with spaces in the name, URL-encoded or nested paths, or clients sending paths with query-like characters inside the segment.","solutions":["URL-encode the filename properly on the client (spaces as %20 still decode to a space and will fail; rename the file instead).","Sanitize/rename the served file to letters, digits, dot, dash or underscore only.","Use a broader macro like {file:path} or {file:string} if arbitrary segments should be accepted."],"exampleFix":"// before\napp.Get(\"/files/{name:file}\", h) // 'my report.pdf' fails\n\n// after\n// rename file to 'my_report.pdf' or use:\napp.Get(\"/files/{name:path}\", h)","handlingStrategy":"validation","validationCode":"const isFile = (s: string) => /^[a-zA-Z0-9_.-]*$/.test(s);\nif (!isFile(filename)) filename = filename.replace(/[^a-zA-Z0-9_.-]/g, '_');","typeGuard":"function isFileName(v: string): boolean {\n  return /^[a-zA-Z0-9_.-]*$/.test(v);\n}","tryCatchPattern":null,"preventionTips":["Rename uploaded/served files to safe characters at write time.","Don't put path separators inside a single {file} segment.","Use {path} macro when nested paths are expected."],"tags":["routing","validation","files","iris"],"backgroundTag":"param-type-mismatch","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}