Skip to content

Commit

Permalink
Attempt to fix replaceRegexpAll
Browse files Browse the repository at this point in the history
  • Loading branch information
vdimir committed Mar 10, 2022
1 parent a506120 commit c66fb7c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/Functions/ReplaceRegexpImpl.h
Expand Up @@ -137,8 +137,13 @@ 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
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 c66fb7c

Please sign in to comment.