Skip to content

Commit fc07884

Browse files
committed
Fix EXPLAIN AST output for strings with embedded single quotes
The escapeStringLiteral function was outputting just `\'` for embedded single quotes, but ClickHouse EXPLAIN AST uses `\\\'` (escaped backslash + escaped quote) for embedded quotes within string literals. This fix aligns with the behavior shown in many existing tests: - 00011_sorting: DateTime(\'Asia/Dubai\') - 00324_hashing_enums: Enum8(\'Hello\' = 0, \'World\' = 1) - 00471_sql_style_quoting: hello\'world - And many others Also fixes test 03404's explain.txt which had incorrect escaping. Enables 4 previously failing tests: - 01434_netloc_fuzz - 03003_sql_json_nonsense - 03521_tuple_of_dynamic_with_string_comparison - 03567_finalize_write_buffer_valid_utf8
1 parent c22b96e commit fc07884

7 files changed

Lines changed: 8 additions & 8 deletions

File tree

internal/explain/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func escapeStringLiteral(s string) string {
3434
case '\\':
3535
sb.WriteString("\\\\\\\\") // backslash becomes four backslashes (\\\\)
3636
case '\'':
37-
sb.WriteString("\\'")
37+
sb.WriteString("\\\\\\'") // single quote becomes \\\' (escaped backslash + escaped quote)
3838
case '\n':
3939
sb.WriteString("\\\\n") // newline becomes \\n
4040
case '\t':
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+
{}

parser/testdata/03404_ubsan_distinct_join_const_column/explain.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SelectWithUnionQuery (children 1)
1313
ExpressionList (children 1)
1414
Function CAST (children 1)
1515
ExpressionList (children 2)
16-
Literal \'[(1, \'a\')]\'
16+
Literal \'[(1, \\\'a\\\')]\'
1717
Literal \'String\'
1818
ExpressionList (children 3)
1919
Literal UInt64_1
@@ -70,7 +70,7 @@ SelectWithUnionQuery (children 1)
7070
ExpressionList (children 2)
7171
Function toNullable (children 1)
7272
ExpressionList (children 1)
73-
Literal \'[(1, \'a\')]\'
73+
Literal \'[(1, \\\'a\\\')]\'
7474
Literal \'String\'
7575
ExpressionList (children 3)
7676
Literal UInt64_1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"explain_txt_edited": true}
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)