{"record":{"id":"bae050c3ccfc030f","repo":"golang/go","slug":"import-path-contains-invalid-character-c-q","errorCode":null,"errorMessage":"import path contains invalid character '%c': %q","messagePattern":"import path contains invalid character '%c': %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/noder/import.go","lineNumber":328,"sourceCode":"\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":310,"sourceCodeEnd":334,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/noder/import.go#L310-L334","documentation":"Returned by checkImportPath when a path rune is one of the explicitly disallowed punctuation characters (!\\\"#$%&'()*,:;<=>?[]^`{|}). These characters conflict with Go syntax, shell metacharacters, go.mod syntax, or URL/path semantics, so import paths reject them.","triggerScenarios":"An import path contains any of ! \\\" # $ % & ' ( ) * , : ; < = > ? [ ] ^ ` { | }; strings.ContainsRune matches and the error names both the character and the full path.","commonSituations":"Pasting a URL-like path with a colon or query string; using a path with brackets for generics-style decoration; shell glob characters leaking into a generated path; quotes around an import literal.","solutions":["Strip or replace the offending punctuation in the import path.","Use only letters, digits, dots, dashes, underscores, and slashes (plus tilde for version selectors handled elsewhere).","Regenerate the import path from sanitized identifiers."],"exampleFix":"// before\n import \"example.com/foo:bar\"\n// after\n import \"example.com/foobar\"","handlingStrategy":"validation","validationCode":"const bad = \"!\\\"#$%&'()*,:;<=>?[]^`{|}\"\nfor _, r := range path {\n    if strings.ContainsRune(bad, r) {\n        return fmt.Errorf(\"invalid character %q in import path\", r)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict import path characters to [A-Za-z0-9._-/].","Generate paths from sanitized identifiers in tooling."],"tags":["go-compiler","import-path","invalid-characters","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}