Skip to content

Commit 64b57e0

Browse files
authored
Add \a and \v escape sequence support and fix raw byte handling (#39)
1 parent 3ea3be0 commit 64b57e0

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

internal/explain/format.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ func FormatFloat(val float64) string {
2727

2828
// escapeStringLiteral escapes special characters in a string for EXPLAIN AST output
2929
// Uses double-escaping as ClickHouse EXPLAIN AST displays strings
30+
// Iterates over bytes to preserve raw bytes (including invalid UTF-8)
3031
func escapeStringLiteral(s string) string {
3132
var sb strings.Builder
32-
for _, r := range s {
33-
switch r {
33+
for i := 0; i < len(s); i++ {
34+
b := s[i]
35+
switch b {
3436
case '\\':
3537
sb.WriteString("\\\\\\\\") // backslash becomes four backslashes (\\\\)
3638
case '\'':
@@ -48,7 +50,7 @@ func escapeStringLiteral(s string) string {
4850
case '\f':
4951
sb.WriteString("\\\\f") // form feed becomes \\f
5052
default:
51-
sb.WriteRune(r)
53+
sb.WriteByte(b)
5254
}
5355
}
5456
return sb.String()

lexer/lexer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,14 @@ func (l *Lexer) readString(quote rune) Item {
376376
sb.WriteRune('\r')
377377
case '0':
378378
sb.WriteRune('\x00')
379+
case 'a':
380+
sb.WriteRune('\a')
379381
case 'b':
380382
sb.WriteRune('\b')
381383
case 'f':
382384
sb.WriteRune('\f')
385+
case 'v':
386+
sb.WriteRune('\v')
383387
case 'x':
384388
// Hex escape: \xNN
385389
l.readChar()
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)