{"record":{"id":"64bad022f1e77abc","repo":"golang/go","slug":"import-path-contains-control-character-q","errorCode":null,"errorMessage":"import path contains control character: %q","messagePattern":"import path contains control character: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/noder/import.go","lineNumber":322,"sourceCode":"\t\treturn errors.New(\"import path is empty\")\n\t}\n\n\tif strings.Contains(path, \"\\x00\") {\n\t\treturn errors.New(\"import path contains NUL\")\n\t}\n\n\tfor ri := range base.ReservedImports {\n\t\tif path == ri {\n\t\t\treturn fmt.Errorf(\"import path %q is reserved and cannot be used\", path)\n\t\t}\n\t}\n\n\tfor _, r := range path {\n\t\tswitch {\n\t\tcase r == utf8.RuneError:\n\t\t\treturn fmt.Errorf(\"import path contains invalid UTF-8 sequence: %q\", path)\n\t\tcase r < 0x20 || r == 0x7f:\n\t\t\treturn fmt.Errorf(\"import path contains control character: %q\", path)\n\t\tcase r == '\\\\':\n\t\t\treturn fmt.Errorf(\"import path contains backslash; use slash: %q\", path)\n\t\tcase !allowSpace && unicode.IsSpace(r):\n\t\t\treturn fmt.Errorf(\"import path contains space character: %q\", path)\n\t\tcase strings.ContainsRune(\"!\\\"#$%&'()*,:;<=>?[]^`{|}\", r):\n\t\t\treturn fmt.Errorf(\"import path contains invalid character '%c': %q\", r, path)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":304,"sourceCodeEnd":334,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/noder/import.go#L304-L334","documentation":"Returned by checkImportPath when a rune in the path is a C0 control character (r < 0x20) or DEL (0x7f). Import paths may not contain control characters because they are not portable across filesystems, shells, or version control.","triggerScenarios":"An import path literal contains a tab, newline, NUL (already guarded separately), backspace, ESC, or DEL; the switch fires the r < 0x20 || r == 0x7f case.","commonSituations":"A multi-line import accidentally containing a literal newline/tab, terminal copy-paste inserting control bytes, or a generated import with embedded formatting characters.","solutions":["Inspect the import line for invisible characters (cat -A or your editor's show-whitespace).","Retype the import path removing all control bytes.","Generate import paths from trusted identifiers only."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for _, r := range path {\n    if r < 0x20 || r == 0x7f {\n        return fmt.Errorf(\"control character in import path\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip control bytes from generated paths.","Show invisible characters in your editor when editing import lines."],"tags":["go-compiler","import-path","control-characters","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}