Skip to content

Commit

Permalink
Merge pull request #35182 from vdimir/regex-replace-35117
Browse files Browse the repository at this point in the history
Fix replaceRegexpAll
  • Loading branch information
alexey-milovidov committed Mar 11, 2022
2 parents 585a9ed + e4e058d commit 38fa55f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Functions/ReplaceRegexpImpl.h
Expand Up @@ -137,8 +137,14 @@ struct ReplaceRegexpImpl

if (replace_one)
can_finish_current_string = true;
else if (match.length() == 0)
++match_pos; /// Step one character to avoid infinite loop.

if (match.length() == 0)
{
/// Step one character to avoid infinite loop
++match_pos;
if (match_pos >= static_cast<size_t>(input.length()))
can_finish_current_string = true;
}
}
else
can_finish_current_string = true;
Expand Down
@@ -1,3 +1,18 @@
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
@@ -1,3 +1,21 @@
select replaceRegexpAll(',,1,,', '^[,]*|[,]*$', '') x;
select replaceRegexpAll(',,1', '^[,]*|[,]*$', '') x;
select replaceRegexpAll('1,,', '^[,]*|[,]*$', '') x;
SELECT replaceRegexpAll(',,1,,', '^[,]*|[,]*$', '');
SELECT replaceRegexpAll(',,1', '^[,]*|[,]*$', '');
SELECT replaceRegexpAll('1,,', '^[,]*|[,]*$', '');

SELECT replaceRegexpAll(materialize(',,1,,'), '^[,]*|[,]*$', '');
SELECT replaceRegexpAll(materialize(',,1'), '^[,]*|[,]*$', '');
SELECT replaceRegexpAll(materialize('1,,'), '^[,]*|[,]*$', '');

SELECT replaceRegexpAll('a', 'z*', '') == 'a';
SELECT replaceRegexpAll('aa', 'z*', '') == 'aa';
SELECT replaceRegexpAll('aaq', 'z*', '') == 'aaq';
SELECT replaceRegexpAll('aazq', 'z*', '') == 'aaq';
SELECT replaceRegexpAll('aazzq', 'z*', '') == 'aaq';
SELECT replaceRegexpAll('aazzqa', 'z*', '') == 'aaqa';

SELECT replaceRegexpAll(materialize('a'), 'z*', '') == 'a';
SELECT replaceRegexpAll(materialize('aa'), 'z*', '') == 'aa';
SELECT replaceRegexpAll(materialize('aaq'), 'z*', '') == 'aaq';
SELECT replaceRegexpAll(materialize('aazq'), 'z*', '') == 'aaq';
SELECT replaceRegexpAll(materialize('aazzq'), 'z*', '') == 'aaq';
SELECT replaceRegexpAll(materialize('aazzqa'), 'z*', '') == 'aaqa';

0 comments on commit 38fa55f

Please sign in to comment.