Skip to content

Commit fece177

Browse files
author
Sergei Golubchik
committed
mysqltest: support pairs of delimiters in replace_regex
1 parent ef2bf18 commit fece177

File tree

5 files changed

+49
-55
lines changed

5 files changed

+49
-55
lines changed

client/mysqltest.cc

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9914,36 +9914,34 @@ struct st_regex
99149914
int reg_replace(char** buf_p, int* buf_len_p, char *pattern, char *replace,
99159915
char *string, int icase);
99169916

9917+
bool parse_re_part(char *start_re, char *end_re,
9918+
char **p, char *end, char **buf)
9919+
{
9920+
if (*start_re != *end_re)
9921+
{
9922+
switch ((*start_re= *(*p)++)) {
9923+
case '(': *end_re= ')'; break;
9924+
case '[': *end_re= ']'; break;
9925+
case '{': *end_re= '}'; break;
9926+
case '<': *end_re= '>'; break;
9927+
default: *end_re= *start_re;
9928+
}
9929+
}
99179930

9931+
while (*p < end && **p != *end_re)
9932+
{
9933+
if ((*p)[0] == '\\' && *p + 1 < end && (*p)[1] == *end_re)
9934+
(*p)++;
99189935

9919-
/*
9920-
Finds the next (non-escaped) '/' in the expression.
9921-
(If the character '/' is needed, it can be escaped using '\'.)
9922-
*/
9936+
*(*buf)++= *(*p)++;
9937+
}
9938+
*(*buf)++= 0;
9939+
9940+
(*p)++;
9941+
9942+
return *p > end;
9943+
}
99239944

9924-
#define PARSE_REGEX_ARG \
9925-
while (p < expr_end) \
9926-
{ \
9927-
char c= *p; \
9928-
if (c == '/') \
9929-
{ \
9930-
if (last_c == '\\') \
9931-
{ \
9932-
buf_p[-1]= '/'; \
9933-
} \
9934-
else \
9935-
{ \
9936-
*buf_p++ = 0; \
9937-
break; \
9938-
} \
9939-
} \
9940-
else \
9941-
*buf_p++ = c; \
9942-
\
9943-
last_c= c; \
9944-
p++; \
9945-
} \
9946-
\
99479945
/*
99489946
Initializes the regular substitution expression to be used in the
99499947
result output of test.
@@ -9955,10 +9953,9 @@ struct st_replace_regex* init_replace_regex(char* expr)
99559953
{
99569954
struct st_replace_regex* res;
99579955
char* buf,*expr_end;
9958-
char* p;
9956+
char* p, start_re, end_re= 1;
99599957
char* buf_p;
99609958
uint expr_len= strlen(expr);
9961-
char last_c = 0;
99629959
struct st_regex reg;
99639960

99649961
/* my_malloc() will die on fail with MY_FAE */
@@ -9976,44 +9973,32 @@ struct st_replace_regex* init_replace_regex(char* expr)
99769973
{
99779974
bzero(&reg,sizeof(reg));
99789975
/* find the start of the statement */
9979-
while (p < expr_end)
9980-
{
9981-
if (*p == '/')
9982-
break;
9976+
while (my_isspace(charset_info, *p) && p < expr_end)
99839977
p++;
9984-
}
99859978

9986-
if (p == expr_end || ++p == expr_end)
9979+
if (p >= expr_end)
99879980
{
99889981
if (res->regex_arr.elements)
99899982
break;
99909983
else
99919984
goto err;
99929985
}
9993-
/* we found the start */
9994-
reg.pattern= buf_p;
9995-
9996-
/* Find first argument -- pattern string to be removed */
9997-
PARSE_REGEX_ARG
99989986

9999-
if (p == expr_end || ++p == expr_end)
10000-
goto err;
9987+
start_re= 0;
9988+
reg.pattern= buf_p;
9989+
if (parse_re_part(&start_re, &end_re, &p, expr_end, &buf_p))
9990+
goto err;
100019991

10002-
/* buf_p now points to the replacement pattern terminated with \0 */
100039992
reg.replace= buf_p;
10004-
10005-
/* Find second argument -- replace string to replace pattern */
10006-
PARSE_REGEX_ARG
10007-
10008-
if (p == expr_end)
10009-
goto err;
10010-
10011-
/* skip the ending '/' in the statement */
10012-
p++;
9993+
if (parse_re_part(&start_re, &end_re, &p, expr_end, &buf_p))
9994+
goto err;
100139995

100149996
/* Check if we should do matching case insensitive */
100159997
if (p < expr_end && *p == 'i')
9998+
{
9999+
p++;
1001610000
reg.icase= 1;
10001+
}
1001710002

1001810003
/* done parsing the statement, now place it in regex_arr */
1001910004
if (insert_dynamic(&res->regex_arr,(uchar*) &reg))

mysql-test/r/mysqltest.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ txt
680680
b is b and more is more
681681
txt
682682
a is a and less is more
683+
sflfdt 'ABCDfF bbddff h' bs txt;
684+
txt
685+
ABCDfF bbddff h
683686
create table t2 ( a char(10));
684687
garbage;
685688
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

mysql-test/suite/rpl/t/rpl_sp.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ show function status like '%mysqltestbug36570%';
614614
connection master;
615615
flush logs;
616616
let $MYSQLD_DATADIR= `select @@datadir`;
617-
--replace_regex s/$MYSQL_TEST_DIR/MYSQL_TEST_DIR/ s/TIMESTAMP=[0-9]*/TIMESTAMP=t/
617+
--replace_regex /$MYSQL_TEST_DIR/MYSQL_TEST_DIR/ /TIMESTAMP=[0-9]*/TIMESTAMP=t/
618618
--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
619619
use test;
620620
drop procedure mysqltestbug36570_p1;

mysql-test/suite/sys_vars/t/report_port_basic.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# only global
44
#
5-
--replace_regex s/[0-9]+/DEFAULT_MASTER_PORT/
5+
--replace_regex /[0-9]+/DEFAULT_MASTER_PORT/
66
select @@global.report_port;
77
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
88
select @@session.report_port;

mysql-test/t/mysqltest.test

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ select "at" as col1, "AT" as col2, "c" as col3;
20532053
--replace_regex /a/b/ /ct/d/
20542054
select "a" as col1, "ct" as col2;
20552055

2056-
--replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/;
2056+
--replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/
20572057
select "strawberry","blueberry","potato";
20582058

20592059
--error 1
@@ -2098,6 +2098,12 @@ select "a is a and less is more" as txt;
20982098
select "a is a and less is more" as txt;
20992099
--enable_query_log
21002100

2101+
#
2102+
# different delimiters
2103+
#
2104+
--replace_regex (a)[b] /c/d/ <e>{f}i {g\/\}}/h/
2105+
select 'ABCDEF abcdef g/}' as txt;
2106+
21012107
#-------------------------------------------------------------------------
21022108
# BUG #11754855 : Passing variable to --error
21032109
#-------------------------------------------------------------------------

0 commit comments

Comments
 (0)