Commit fece177f authored by Sergei Golubchik's avatar Sergei Golubchik

mysqltest: support pairs of delimiters in replace_regex

parent ef2bf187
......@@ -9914,36 +9914,34 @@ struct st_regex
int reg_replace(char** buf_p, int* buf_len_p, char *pattern, char *replace,
char *string, int icase);
bool parse_re_part(char *start_re, char *end_re,
char **p, char *end, char **buf)
{
if (*start_re != *end_re)
{
switch ((*start_re= *(*p)++)) {
case '(': *end_re= ')'; break;
case '[': *end_re= ']'; break;
case '{': *end_re= '}'; break;
case '<': *end_re= '>'; break;
default: *end_re= *start_re;
}
}
while (*p < end && **p != *end_re)
{
if ((*p)[0] == '\\' && *p + 1 < end && (*p)[1] == *end_re)
(*p)++;
/*
Finds the next (non-escaped) '/' in the expression.
(If the character '/' is needed, it can be escaped using '\'.)
*/
*(*buf)++= *(*p)++;
}
*(*buf)++= 0;
(*p)++;
return *p > end;
}
#define PARSE_REGEX_ARG \
while (p < expr_end) \
{ \
char c= *p; \
if (c == '/') \
{ \
if (last_c == '\\') \
{ \
buf_p[-1]= '/'; \
} \
else \
{ \
*buf_p++ = 0; \
break; \
} \
} \
else \
*buf_p++ = c; \
\
last_c= c; \
p++; \
} \
\
/*
Initializes the regular substitution expression to be used in the
result output of test.
......@@ -9955,10 +9953,9 @@ struct st_replace_regex* init_replace_regex(char* expr)
{
struct st_replace_regex* res;
char* buf,*expr_end;
char* p;
char* p, start_re, end_re= 1;
char* buf_p;
uint expr_len= strlen(expr);
char last_c = 0;
struct st_regex reg;
/* my_malloc() will die on fail with MY_FAE */
......@@ -9976,44 +9973,32 @@ struct st_replace_regex* init_replace_regex(char* expr)
{
bzero(&reg,sizeof(reg));
/* find the start of the statement */
while (p < expr_end)
{
if (*p == '/')
break;
while (my_isspace(charset_info, *p) && p < expr_end)
p++;
}
if (p == expr_end || ++p == expr_end)
if (p >= expr_end)
{
if (res->regex_arr.elements)
break;
else
goto err;
}
/* we found the start */
reg.pattern= buf_p;
/* Find first argument -- pattern string to be removed */
PARSE_REGEX_ARG
if (p == expr_end || ++p == expr_end)
start_re= 0;
reg.pattern= buf_p;
if (parse_re_part(&start_re, &end_re, &p, expr_end, &buf_p))
goto err;
/* buf_p now points to the replacement pattern terminated with \0 */
reg.replace= buf_p;
/* Find second argument -- replace string to replace pattern */
PARSE_REGEX_ARG
if (p == expr_end)
if (parse_re_part(&start_re, &end_re, &p, expr_end, &buf_p))
goto err;
/* skip the ending '/' in the statement */
p++;
/* Check if we should do matching case insensitive */
if (p < expr_end && *p == 'i')
{
p++;
reg.icase= 1;
}
/* done parsing the statement, now place it in regex_arr */
if (insert_dynamic(&res->regex_arr,(uchar*) &reg))
......
......@@ -680,6 +680,9 @@ txt
b is b and more is more
txt
a is a and less is more
sflfdt 'ABCDfF bbddff h' bs txt;
txt
ABCDfF bbddff h
create table t2 ( a char(10));
garbage;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'garbage' at line 1
......
......@@ -614,7 +614,7 @@ show function status like '%mysqltestbug36570%';
connection master;
flush logs;
let $MYSQLD_DATADIR= `select @@datadir`;
--replace_regex s/$MYSQL_TEST_DIR/MYSQL_TEST_DIR/ s/TIMESTAMP=[0-9]*/TIMESTAMP=t/
--replace_regex /$MYSQL_TEST_DIR/MYSQL_TEST_DIR/ /TIMESTAMP=[0-9]*/TIMESTAMP=t/
--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
use test;
drop procedure mysqltestbug36570_p1;
......
......@@ -2,7 +2,7 @@
#
# only global
#
--replace_regex s/[0-9]+/DEFAULT_MASTER_PORT/
--replace_regex /[0-9]+/DEFAULT_MASTER_PORT/
select @@global.report_port;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
select @@session.report_port;
......
......@@ -2053,7 +2053,7 @@ select "at" as col1, "AT" as col2, "c" as col3;
--replace_regex /a/b/ /ct/d/
select "a" as col1, "ct" as col2;
--replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/;
--replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/
select "strawberry","blueberry","potato";
--error 1
......@@ -2098,6 +2098,12 @@ select "a is a and less is more" as txt;
select "a is a and less is more" as txt;
--enable_query_log
#
# different delimiters
#
--replace_regex (a)[b] /c/d/ <e>{f}i {g\/\}}/h/
select 'ABCDEF abcdef g/}' as txt;
#-------------------------------------------------------------------------
# BUG #11754855 : Passing variable to --error
#-------------------------------------------------------------------------
......
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