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