Skip to content

Commit 5b2b373

Browse files
Merge pull request ClickHouse#11318 from devwout/master
Fix visitParamExtractRaw for strings with unbalanced { or [.
2 parents 85537d7 + 70eaae3 commit 5b2b373

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/Functions/visitParamExtractRaw.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ struct ExtractRaw
2222
expects_end.pop_back();
2323
current_expect_end = expects_end.empty() ? 0 : expects_end.back();
2424
}
25+
else if (current_expect_end == '"')
26+
{
27+
/// skip backslash
28+
if (*pos == '\\' && pos + 1 < end && pos[1] == '"')
29+
{
30+
pos++;
31+
}
32+
}
2533
else
2634
{
2735
switch (*pos)
@@ -38,11 +46,6 @@ struct ExtractRaw
3846
current_expect_end = '"';
3947
expects_end.push_back(current_expect_end);
4048
break;
41-
case '\\':
42-
/// skip backslash
43-
if (pos + 1 < end && pos[1] == '"')
44-
pos++;
45-
break;
4649
default:
4750
if (!current_expect_end && (*pos == ',' || *pos == '}'))
4851
{

tests/queries/0_stateless/00539_functions_for_working_with_json.reference

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ test"string
99
"test_string"
1010
"test\\"string"
1111
"test\\"string"
12+
"{"
13+
"["
1214
["]", "2", "3"]
1315
{"nested" : [1,2,3]}

tests/queries/0_stateless/00539_functions_for_working_with_json.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ SELECT visitParamExtractRaw('{"myparam":"test_string"}', 'myparam');
1111
SELECT visitParamExtractRaw('{"myparam": "test_string"}', 'myparam');
1212
SELECT visitParamExtractRaw('{"myparam": "test\\"string"}', 'myparam');
1313
SELECT visitParamExtractRaw('{"myparam": "test\\"string", "other":123}', 'myparam');
14+
SELECT visitParamExtractRaw('{"myparam": "{"}', 'myparam');
15+
SELECT visitParamExtractRaw('{"myparam": "["}', 'myparam');
1416
SELECT visitParamExtractRaw('{"myparam": ["]", "2", "3"], "other":123}', 'myparam');
1517
SELECT visitParamExtractRaw('{"myparam": {"nested" : [1,2,3]}, "other":123}', 'myparam');

0 commit comments

Comments
 (0)