{"record":{"id":"278c6b6f6b1163cd","repo":"golang/go","slug":"unterminated-c-string","errorCode":null,"errorMessage":"unterminated %c string","messagePattern":"unterminated %c string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/quoted/quoted.go","lineNumber":45,"sourceCode":"\t// Quotes further inside the string do not count.\n\tvar f []string\n\tfor len(s) > 0 {\n\t\tfor len(s) > 0 && isSpaceByte(s[0]) {\n\t\t\ts = s[1:]\n\t\t}\n\t\tif len(s) == 0 {\n\t\t\tbreak\n\t\t}\n\t\t// Accepted quoted string. No unescaping inside.\n\t\tif s[0] == '\"' || s[0] == '\\'' {\n\t\t\tquote := s[0]\n\t\t\ts = s[1:]\n\t\t\ti := 0\n\t\t\tfor i < len(s) && s[i] != quote {\n\t\t\t\ti++\n\t\t\t}\n\t\t\tif i >= len(s) {\n\t\t\t\treturn nil, fmt.Errorf(\"unterminated %c string\", quote)\n\t\t\t}\n\t\t\tf = append(f, s[:i])\n\t\t\ts = s[i+1:]\n\t\t\tcontinue\n\t\t}\n\t\ti := 0\n\t\tfor i < len(s) && !isSpaceByte(s[i]) {\n\t\t\ti++\n\t\t}\n\t\tf = append(f, s[:i])\n\t\ts = s[i:]\n\t}\n\treturn f, nil\n}\n\n// Join joins a list of arguments into a string that can be parsed\n// with Split. Arguments are quoted only if necessary; arguments\n// without spaces or quotes are kept as-is. No argument may contain both","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/quoted/quoted.go#L27-L63","documentation":"Thrown by the Split function when a quoted string (delimited by either single ' or double \" quotes) has no matching closing quote before end-of-input. The scanner advances past the opening quote character but reaches the end of the string without finding the same quote character again. The %c formats the unmatched quote character for identification.","triggerScenarios":"Input string starts with ' or \" but the corresponding closing delimiter is absent. The for loop `for i < len(s) && s[i] != quote` exits because i >= len(s) without finding the closing quote.","commonSituations":"Malformed command-line flag values (e.g. cmd/link's -extldflags) where a quoted argument is missing its closing quote. Typographical errors in configuration strings, copy-paste issues, or shell-escaping mistakes that drop a closing quote.","solutions":["Add the missing closing quote character to the input string.","Validate input strings are properly balanced before passing to Split.","Check for shell-escaping issues that may have consumed a quote character."],"exampleFix":"// Before (broken): quoted.Split(`-foo 'bar`)\n// After (fixed):  quoted.Split(`-foo 'bar'`)","handlingStrategy":"validation","validationCode":"// Validate quote balance before calling Split:\nfunc validateQuotes(s string) error {\n    for i := 0; i < len(s); i++ {\n        if s[i] == '\\'' || s[i] == '\"' {\n            quote := s[i]\n            found := false\n            for j := i + 1; j < len(s); j++ {\n                if s[j] == quote {\n                    found = true\n                    break\n                }\n            }\n            if !found {\n                return fmt.Errorf(\"unterminated %c quote at position %d\", quote, i)\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair opening and closing quote characters in flag strings.","Validate string inputs for balanced quotes before passing to quoted.Split.","Use shell-escaping utilities to properly format multi-word flag values."],"tags":["quoted","parsing","unterminated-string","go-compiler-internal"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}