diff options
author | Sergei Golubchik <sergii@pisem.net> | 2014-08-04 21:19:24 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2014-08-04 21:19:24 +0200 |
commit | fece177fe262f3e1d5438afd8d5faa8b60e9b2dd (patch) | |
tree | 616dadd2ee67c024517eb345727c14bb0cd69619 | |
parent | ef2bf1870622b5167066ea95e7824631d93bbf3f (diff) | |
download | mariadb-git-fece177fe262f3e1d5438afd8d5faa8b60e9b2dd.tar.gz |
mysqltest: support pairs of delimiters in replace_regex
-rw-r--r-- | client/mysqltest.cc | 89 | ||||
-rw-r--r-- | mysql-test/r/mysqltest.result | 3 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_sp.test | 2 | ||||
-rw-r--r-- | mysql-test/suite/sys_vars/t/report_port_basic.test | 2 | ||||
-rw-r--r-- | mysql-test/t/mysqltest.test | 8 |
5 files changed, 49 insertions, 55 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 464ec0f0199..41f1d074dd9 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -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(®,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) - goto err; + 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) - goto err; - - /* skip the ending '/' in the statement */ - p++; + if (parse_re_part(&start_re, &end_re, &p, expr_end, &buf_p)) + goto err; /* 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*) ®)) diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 7228daa2712..e258b1d156f 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -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 diff --git a/mysql-test/suite/rpl/t/rpl_sp.test b/mysql-test/suite/rpl/t/rpl_sp.test index 00815ab9d7e..c978a145a92 100644 --- a/mysql-test/suite/rpl/t/rpl_sp.test +++ b/mysql-test/suite/rpl/t/rpl_sp.test @@ -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; diff --git a/mysql-test/suite/sys_vars/t/report_port_basic.test b/mysql-test/suite/sys_vars/t/report_port_basic.test index 903289230bd..dfe64dd4e8d 100644 --- a/mysql-test/suite/sys_vars/t/report_port_basic.test +++ b/mysql-test/suite/sys_vars/t/report_port_basic.test @@ -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; diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index ffbec36873e..ae59c713c3d 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -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 #------------------------------------------------------------------------- |