{"record":{"id":"4f416f228a9ac329","repo":"1Panel-dev/1Panel","slug":"unexpected-end-of-file-while-scanning-a-string-ma-4f416f","errorCode":null,"errorMessage":"unexpected end of file while scanning a string, maybe an unclosed quote?","messagePattern":"unexpected end of file while scanning a string, maybe an unclosed quote\\?","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/utils/nginx/parser/lexer.go","lineNumber":175,"sourceCode":"}\n\nfunc (s *lexer) skipWhitespace() {\n\ts.readWhile(isSpace)\n}\n\nfunc (s *lexer) scanComment() flag.Flag {\n\treturn s.NewToken(flag.Comment).Lit(s.readUntil(isEndOfLine))\n}\n\nfunc (s *lexer) scanQuotedString(delimiter rune) flag.Flag {\n\tvar buf bytes.Buffer\n\ttok := s.NewToken(flag.QuotedString)\n\t_, _ = buf.WriteRune(s.read())\n\tfor {\n\t\tch := s.read()\n\n\t\tif ch == rune(flag.EOF) {\n\t\t\tpanic(\"unexpected end of file while scanning a string, maybe an unclosed quote?\")\n\t\t}\n\n\t\tif ch == '\\\\' && (s.peek() == delimiter) {\n\t\t\tbuf.WriteRune(ch)\n\t\t\tbuf.WriteRune(s.read())\n\t\t\tcontinue\n\t\t}\n\n\t\t_, _ = buf.WriteRune(ch)\n\t\tif ch == delimiter {\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn tok.Lit(buf.String())\n}\n\nfunc (s *lexer) scanKeyword() flag.Flag {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/1Panel-dev/1Panel/blob/5ac7c808815b0691009cd390414f03471312262f/agent/utils/nginx/parser/lexer.go#L157-L193","documentation":"Panic in lexer.scanQuotedString when EOF arrives before the closing quote of a quoted token (the delimiter rune never reappeared). Escaped delimiters (\\\" inside \"...\") are handled, so this means a genuinely unterminated string literal in the nginx config.","triggerScenarios":"Parsing a config with a directive like proxy_set_header X-Foo \"bar; or return 301 'target; — the opening \" or ' is never closed before end of file.","commonSituations":"Hand-editing a regex or header value and dropping the closing quote; a generated config where a variable expanded to text containing a quote; copy-paste truncation.","solutions":["Locate the last edited quoted value (grep -n '\"' file and check odd counts) and close the literal","Escape embedded quotes as \\\" rather than leaving them bare","Run nginx -t before reloading so syntax errors surface outside the agent's parser"],"exampleFix":"# before\nproxy_set_header X-Long \"shortened;\n# after\nproxy_set_header X-Long \"shortened\";","handlingStrategy":"validation","validationCode":"python3 - <<'PY'\nimport sys, re\nfor i, line in enumerate(open(sys.argv[1]), 1):\n    for q in ('\"', \"'\"):\n        if len(re.findall(q, line)) % 2 == 1:\n            print(f'odd {q!r} count on line {i}: {line.rstrip()}')\nPY <config-file>","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep quotes paired on a single line in nginx configs; escape \\\" inside values","nginx -t before reload; it reports unterminated strings with line numbers"],"tags":["nginx","lexer","quoting","go","panic"],"backgroundTag":null,"analyzedSha":"5ac7c808815b0691009cd390414f03471312262f","analyzedAt":"2026-08-15T14:02:06.953Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}