Do not stay in the escape state after a backslash-newline in StringLiteral

The empty case '\n' in the backslash state was meant to drop a
backslash-newline pair like Python's python_string does, but it never
reset the state, so the next character was parsed as an escape.
This commit is contained in:
devangpratap 2026-09-29 12:27:24 -04:00
parent c73326a9d8
commit 632265ec33
2 changed files with 3 additions and 0 deletions

View file

@ -121,6 +121,7 @@ func StringLiteral(val string) (string, error) {
case backslash:
switch ch {
case '\n':
state = normal
case '\\':
ans.WriteRune('\\')
state = normal

View file

@ -18,6 +18,8 @@ func TestStringLiteralParsing(t *testing.T) {
`abc`: `abc`,
`a\nb\M`: "a\nb\\M",
`a\x20\x1\u1234\123\12|`: "a \\x1\u1234\123\x0a|",
"a\\\nnb": "anb",
"a\\\n\\tb": "a\tb",
} {
actual, err := StringLiteral(q)
if err != nil {