Skip to content

Commit b8578f4

Browse files
committed
Fix unknown escape sequences in string literals to preserve backslash
Previously, when the lexer encountered an unknown escape sequence like \S in a string, it would only write the character after the backslash, losing the backslash itself. This caused strings like 'Win\Sys' to be stored as 'WinSys' instead of 'Win\Sys'. This fix preserves both the backslash and the following character for unknown escape sequences, matching ClickHouse's behavior. Enables 5 passing tests.
1 parent c32dede commit b8578f4

6 files changed

Lines changed: 7 additions & 6 deletions

File tree

lexer/lexer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ func (l *Lexer) readString(quote rune) Item {
397397
val := hexValue(hex1)*16 + hexValue(hex2)
398398
sb.WriteByte(byte(val))
399399
default:
400-
// Unknown escape, just write the character after backslash
400+
// Unknown escape, preserve both the backslash and the character
401+
sb.WriteRune('\\')
401402
sb.WriteRune(l.ch)
402403
}
403404
l.readChar()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)