Commit 9e820201 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-6965 non-captured group \2 in regexp_replace

parent 080fdbf9
...@@ -839,3 +839,9 @@ SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2'); ...@@ -839,3 +839,9 @@ SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2');
REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2') REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2')
/abc /abc
SET default_regex_flags=DEFAULT; SET default_regex_flags=DEFAULT;
#
# MDEV-6965 non-captured group \2 in regexp_replace
#
SELECT REGEXP_REPLACE('1 foo and bar', '(\\d+) foo and (\\d+ )?bar', '\\1 this and \\2that');
REGEXP_REPLACE('1 foo and bar', '(\\d+) foo and (\\d+ )?bar', '\\1 this and \\2that')
1 this and that
......
...@@ -397,3 +397,8 @@ SET default_regex_flags='UNGREEDY'; ...@@ -397,3 +397,8 @@ SET default_regex_flags='UNGREEDY';
SELECT REGEXP_SUBSTR('abc','.+'); SELECT REGEXP_SUBSTR('abc','.+');
SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2'); SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2');
SET default_regex_flags=DEFAULT; SET default_regex_flags=DEFAULT;
--echo #
--echo # MDEV-6965 non-captured group \2 in regexp_replace
--echo #
SELECT REGEXP_REPLACE('1 foo and bar', '(\\d+) foo and (\\d+ )?bar', '\\1 this and \\2that');
...@@ -1379,13 +1379,16 @@ bool Item_func_regexp_replace::append_replacement(String *str, ...@@ -1379,13 +1379,16 @@ bool Item_func_regexp_replace::append_replacement(String *str,
break; /* End of line */ break; /* End of line */
beg+= cnv; beg+= cnv;
if ((n= ((int) wc) - '0') >= 0 && n <= 9 && n < re.nsubpatterns()) if ((n= ((int) wc) - '0') >= 0 && n <= 9)
{
if (n < re.nsubpatterns())
{ {
/* A valid sub-pattern reference found */ /* A valid sub-pattern reference found */
int pbeg= re.subpattern_start(n), plength= re.subpattern_end(n) - pbeg; int pbeg= re.subpattern_start(n), plength= re.subpattern_end(n) - pbeg;
if (str->append(source->str + pbeg, plength, cs)) if (str->append(source->str + pbeg, plength, cs))
return true; return true;
} }
}
else else
{ {
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment