Skip to content

Commit

Permalink
YQL-17057: Fix escaping (#1664)
Browse files Browse the repository at this point in the history
* YQL-17057: Fix escaping

* test
  • Loading branch information
MrLolthe1st authored Feb 7, 2024
1 parent 8fd6a95 commit 72d2d86
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ydb/library/yql/udfs/common/re2/re2_udf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,14 @@ namespace {
default:
if (hasEscape && c == escape) {
if (escapeOn) {
result << c;
result << RE2::QuoteMeta(StringPiece(&c, 1));
}
escapeOn = !escapeOn;
} else {
if (slash)
result << '\\';
result << c;
escapeOn = false;
}
slash = false;
break;
Expand Down
5 changes: 5 additions & 0 deletions ydb/library/yql/udfs/common/re2/test/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"uri": "file://test.test_DefOptions_/results.txt"
}
],
"test.test[LikeEscape]": [
{
"uri": "file://test.test_LikeEscape_/results.txt"
}
],
"test.test[MultipleCaptureGroups]": [
{
"uri": "file://test.test_MultipleCaptureGroups_/extracted"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[
{
"Write" = [
{
"Type" = [
"ListType";
[
"StructType";
[
[
"column0";
[
"DataType";
"Bool"
]
];
[
"column1";
[
"DataType";
"Bool"
]
];
[
"column2";
[
"DataType";
"Bool"
]
];
[
"column3";
[
"DataType";
"Bool"
]
];
[
"column4";
[
"DataType";
"Bool"
]
];
[
"column5";
[
"DataType";
"Bool"
]
];
[
"column6";
[
"DataType";
"Bool"
]
]
]
]
];
"Data" = [
[
%true;
%true;
%true;
%true;
%true;
%true;
%false
]
]
}
]
}
]
7 changes: 7 additions & 0 deletions ydb/library/yql/udfs/common/re2/test/cases/LikeEscape.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT '?' LIKE '%??%' ESCAPE '?',
'x_' LIKE '%xxx_' ESCAPE 'x',
'[' LIKE '[' ESCAPE '!',
'.' LIKE '..' ESCAPE '.',
'[' LIKE '[[' ESCAPE '[',
'a%b' LIKE '.a.%.b' ESCAPE '.',
'x' LIKE '..' ESCAPE '.';

0 comments on commit 72d2d86

Please sign in to comment.