[MDEV-14620] Regexp not matching dash (-) Created: 2017-12-11  Updated: 2017-12-12  Resolved: 2017-12-12

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 5.5.56
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Dron Kram Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None
Environment:
  1. cat /etc/centos-release
    CentOS Linux release 7.4.1708 (Core)
    yum list installed | grep maria
    mariadb.x86_64 1:5.5.56-2.el7 @base
    mariadb-libs.x86_64 1:5.5.56-2.el7 @anaconda
    mariadb-server.x86_64 1:5.5.56-2.el7 @base


 Description   

Hello.
Need to use regexp aliases with Postfixadmin.
Standard Postfixadmin alias table

 CREATE TABLE `alias` (
  `address` varchar(255) NOT NULL,
  `goto` text NOT NULL,
  `domain` varchar(255) NOT NULL,
  `created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
  `modified` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`address`),
  KEY `domain` (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Aliases'

Inserted alias with regexp

INSERT INTO alias VALUES ('tks\.[0-9a-z\-\_\.]+@example.com','tks@example.com','example.com',NOW(),NOW(),1);

Selecting email with dash returns empty dataset

SELECT goto FROM alias WHERE 'tks.te-st@example.com' REGEXP CONCAT('^',address,'$') AND SUBSTRING(address,1,1) != '@';
Empty set (0.00 sec)

Point (tks.te.st@example.com) and underscore (tks.te_st@example.com) matches well.

Checked same on MySQL 5.1.73 - dash matching without any problem.



 Comments   
Comment by Dron Kram [ 2017-12-12 ]

Updated MariaDB to 10.0 version from IUS repo and in this version matching of dash works well.

Comment by Alexander Barkov [ 2017-12-12 ]

In 10.0, MariaDB switched to PCRE instead of Henry Spencer's regexp library.
PCRE is more flexible in interpreting dash characters inside square brackets, while the old library requires the dash to be the last character inside the range.

So in versions before 10.0, instead of:

INSERT INTO alias VALUES ('tks\.[0-9a-z\-\_\.]+@example.com','tks@example.com','example.com',NOW(),NOW(),1);

please use:

INSERT INTO alias VALUES ('tks\.[0-9a-z\_\.\-]+@example.com','tks@example.com','example.com',NOW(),NOW(),1);

Comment by Alexander Barkov [ 2017-12-12 ]

Btw, with MySQL-5.1.72 it also returns empty set.
Moving dash to the last position inside the brackets fixes the problem.

Generated at Thu Feb 08 08:14:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.