Bug #82921 regex return inconsistent results with invalid pattern
Submitted: 9 Sep 2016 8:29 Modified: 24 Dec 2019 15:30
Reporter: 帅 Bang Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.6 OS:Linux
Assigned to: CPU Architecture:Any

[9 Sep 2016 8:29] 帅 Bang
Description:
mysql> drop table if exists t1;
Query OK, 0 rows affected (0.01 sec)

mysql> create table t1 (s1 varchar(64) character set utf8mb4 default null, s2 varchar(64) character set utf8mb4 default null);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values('abc','abc[');
Query OK, 1 row affected (0.00 sec)

mysql> select s1 regexp s2 from t1;
+--------------+
| s1 regexp s2 |
+--------------+
|         NULL |
+--------------+
1 row in set (0.00 sec)

yeah, this is quite good so far. However, when we type select 'abc' regexp 'abc[' , we got :

mysql> select 'abc' regexp 'abc[';
ERROR 1139 (42000): Got error 'brackets ([ ]) not balanced' from regexp

What a pity, it failed.

How to repeat:
drop table if exists t1; 

create table t1 (s1 varchar(64) character set utf8mb4 default null, s2 varchar(64) character set utf8mb4 default null);

insert into t1 values('abc','abc[');

select s1 regexp s2 from t1;

select 'abc' regexp 'abc[';

Suggested fix:
select 'abc' regexp 'abc['; returns NULL with a warning
[9 Sep 2016 9:25] MySQL Verification Team
Hello Bang,

Thank you for the report.
This is observed in 5.1.77, 5.5.51, 5.6.32, 5.7.14/15.

Thanks,
Umesh
[24 Dec 2019 15:30] Roy Lyseng
Posted by developer:
 
Fixed in 8.0.18.
Returns an error about unclosed bracket in both cases.