{"record":{"id":"a38787470dded6a2","repo":"hashicorp/terraform","slug":"error-parsing-github-url-s","errorCode":null,"errorMessage":"error parsing GitHub URL: %s","messagePattern":"error parsing GitHub URL: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getmodules/moduleaddrs/detect_git.go","lineNumber":54,"sourceCode":"// translates them into git HTTP source addresses.\nfunc detectGitHub(src string) (string, bool, error) {\n\tif len(src) == 0 {\n\t\treturn \"\", false, nil\n\t}\n\n\tif strings.HasPrefix(src, \"github.com/\") {\n\t\tsrc, rawQuery, _ := strings.Cut(src, \"?\")\n\n\t\tparts := strings.Split(src, \"/\")\n\t\tif len(parts) < 3 {\n\t\t\treturn \"\", false, fmt.Errorf(\n\t\t\t\t\"GitHub URLs should be github.com/username/repo\")\n\t\t}\n\n\t\turlStr := fmt.Sprintf(\"https://%s\", strings.Join(parts[:3], \"/\"))\n\t\turl, err := url.Parse(urlStr)\n\t\tif err != nil {\n\t\t\treturn \"\", true, fmt.Errorf(\"error parsing GitHub URL: %s\", err)\n\t\t}\n\t\turl.RawQuery = rawQuery\n\n\t\tif !strings.HasSuffix(url.Path, \".git\") {\n\t\t\turl.Path += \".git\"\n\t\t}\n\n\t\tif len(parts) > 3 {\n\t\t\turl.Path += \"//\" + strings.Join(parts[3:], \"/\")\n\t\t}\n\n\t\treturn \"git::\" + url.String(), true, nil\n\t}\n\n\treturn \"\", false, nil\n}\n\n// detectBitBucket detects shorthand schemeless references to bitbucket.org and","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/getmodules/moduleaddrs/detect_git.go#L36-L72","documentation":"Returned by detectGitHub (detect_git.go:54) when url.Parse fails on the https URL assembled from the first three github.com path segments. After constructing https://github.com/<username>/<repo>, net/url.Parse rejects it. This is uncommon because the constructed URL is simple, but invalid characters in the username/repo segments can trigger it.","triggerScenarios":"A github.com shorthand source whose username or repo segment contains characters that make the assembled https URL unparseable by net/url.Parse (e.g. spaces, control chars, bad percent-encoding).","commonSituations":"A username or repo name with spaces, uppercase with stray characters, or a copy-paste that includes surrounding quotes/whitespace. A source string with embedded newlines or tabs. Misencoded special characters.","solutions":["Trim whitespace and stray characters from the source string; ensure only valid GitHub username/repo characters (alphanumeric, dash, underscore, dot).","URL-encode any legitimately special characters in the path segments.","Use the full https URL form directly: source = \"git::https://github.com/user/repo.git\".","Check the parse error detail in the message for the offending token."],"exampleFix":"# before — stray trailing space / invalid char\nsource = \"github.com/user repo\"\n\n# after — valid github shorthand\nsource = \"github.com/user/repo\"","handlingStrategy":"validation","validationCode":"// Pre-parse the assembled GitHub URL to catch bad characters\nfunc githubURLParses(src string) bool {\n    if !strings.HasPrefix(src, \"github.com/\") {\n        return true\n    }\n    parts := strings.Split(strings.SplitN(src, \"?\", 2)[0], \"/\")\n    if len(parts) < 3 {\n        return false\n    }\n    _, err := url.Parse(\"https://\" + strings.Join(parts[:3], \"/\"))\n    return err == nil\n}","typeGuard":"func githubURLParses(src string) bool {\n    parts := strings.Split(strings.SplitN(src, \"?\", 2)[0], \"/\")\n    if len(parts) < 3 {\n        return false\n    }\n    _, err := url.Parse(\"https://\" + strings.Join(parts[:3], \"/\"))\n    return err == nil\n}","tryCatchPattern":null,"preventionTips":["Trim whitespace and quotes from module source strings before use.","Restrict GitHub shorthand to valid username/repo characters.","Fall back to the explicit git::https://github.com/user/repo.git form for edge cases."],"tags":["getmodules","github","module-source","url-parsing","modules"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}