{"id":"21cd5d3b4cea285b","repo":"jackc/pgx","slug":"unterminated-quoted-string-in-connection-info-stri","errorCode":null,"errorMessage":"unterminated quoted string in connection info string","messagePattern":"unterminated quoted string in connection info string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/config.go","lineNumber":763,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t\tval = strings.ReplaceAll(strings.ReplaceAll(s[:end], \"\\\\\\\\\", \"\\\\\"), \"\\\\'\", \"'\")\n\t\t\t// Consume the value and trim any subsequent whitespace so that\n\t\t\t// multiple trailing spaces don't cause a spurious parse failure.\n\t\t\ts = strings.TrimLeft(s[end:], \" \\t\\n\\r\\v\\f\")\n\t\tdefault: // quoted string\n\t\t\ts = s[1:]\n\t\t\tend := 0\n\t\t\tfor ; end < len(s); end++ {\n\t\t\t\tif s[end] == '\\'' {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif s[end] == '\\\\' {\n\t\t\t\t\tend++\n\t\t\t\t}\n\t\t\t}\n\t\t\tif end == len(s) {\n\t\t\t\treturn nil, errors.New(\"unterminated quoted string in connection info string\")\n\t\t\t}\n\t\t\tval = strings.ReplaceAll(strings.ReplaceAll(s[:end], \"\\\\\\\\\", \"\\\\\"), \"\\\\'\", \"'\")\n\t\t\t// Consume the closing quote and any subsequent whitespace.\n\t\t\ts = strings.TrimLeft(s[end+1:], \" \\t\\n\\r\\v\\f\")\n\t\t}\n\n\t\tkey = canonicalConnStringKey(key)\n\n\t\tif key == \"\" {\n\t\t\treturn nil, errors.New(\"invalid keyword/value\")\n\t\t}\n\n\t\tif key == \"user\" && val == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tsettings[key] = val\n\t}\n","sourceCodeStart":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/config.go#L745-L781","documentation":"Returned by parseKeywordValueSettings while parsing a single-quoted value: the closing quote is never found before end-of-string. The parser scans until it runs out of bytes without encountering the terminating ', so the quoted value is unterminated.","triggerScenarios":"A keyword/value string with an unclosed single-quoted value, e.g. \"password='secret\" or \"dbname='my db\". Common when a value contains spaces and the opening quote is added but the closing one is dropped.","commonSituations":"Building conninfo dynamically and forgetting to close a quote; values with spaces/apostrophes mishandled; shell quoting eating the closing quote.","solutions":["Add the missing closing single-quote: \"password='secret'\".","To include a literal quote inside a quoted value, escape it as \\' or double it per libpq rules.","Prefer passing a URL connection string or building a *ConnConfig to avoid manual quoting."],"exampleFix":"// before\npgx.ParseConfig(`user=app password='secret`)\n\n// after\npgx.ParseConfig(`user=app password='secret'`)","handlingStrategy":"validation","validationCode":"// Ensure every opened single-quote in conninfo is closed.\nfunc validateQuotesBalanced(s string) error {\n    inQuote := false\n    for i := 0; i < len(s); i++ {\n        if s[i] == '\\'' {\n            inQuote = !inQuote\n        }\n    }\n    if inQuote {\n        return errors.New(\"unterminated quoted string in connection info string\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := pgx.ParseConfig(connStr); err != nil {\n    if strings.Contains(err.Error(), \"unterminated quoted string\") {\n        return fmt.Errorf(\"connection string has an unclosed quote: %w\", err)\n    }\n}","preventionTips":["Always close single-quoted values; escape literal quotes as \\\\'.","For values with spaces/special chars, prefer URL DSN encoding or *ConnConfig.","Lint dynamically built conninfo before use."],"tags":["config","connection-string","parsing","quoting"],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}