Bug #76188 [Opn]: Change in treating unescaped - in character classes
| From: | cmb@php.net | Date: | Thu, 05 Apr 2018 16:48:56 +0000 |
| Subject: | Bug #76188 [Opn]: Change in treating unescaped - in character classes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214626@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76188&edit=1
ID: 76188
Updated by: cmb@php.net
Reported by: andi at splitbrain dot org
Summary: Change in treating unescaped - in character classes
Status: Open
Type: Bug
Package: PCRE related
Operating System: Linux
PHP Version: master-Git-2018-04-05 (Git)
Block user comment: N
Private report: N
New Comment:
That's likely a behavioral difference between PCRE and PCRE2.
Previous Comments:
------------------------------------------------------------------------
[2018-04-05 15:18:11] andi at splitbrain dot org
Description:
------------
In regular expressions an unescaped minus character (-) in character classes is usually used to
declare a range. However when the range makes no sense, it is treated as a literal minus character.
This seems still to be true for most occasions in 7.3-dev except for one special combination, where
the minus sits between a shortcut character class and a dollar sign. Eg. /[\w-$]/. Previous PHP
versions would treat this as word characters, minus and dollar. PHP 7.3-dev throws an error.
Test script:
---------------
<?php
$tests = [
'/[\w-$]/',
'/[\w-]/',
'/[-\w]/',
'/[$-]/',
'/[-$]/',
];
echo PHP_VERSION;
echo "\n";
foreach($tests as $test) {
echo "$test\n";
preg_match($test,'');
}
Expected result:
----------------
7.2.3
/[\w-$]/
/[\w-]/
/[-\w]/
/[$-]/
/[-$]/
Actual result:
--------------
7.3.0-dev
/[\w-$]/
Warning: preg_match(): Compilation failed: invalid range in character class at offset 3 in
/var/www/test.php on line 16
/[\w-]/
/[-\w]/
/[$-]/
/[-$]/
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76188&edit=1