Bug #76909 [Opn]: preg_match difference between 7.3 and < 7.3
| From: | requinix@php.net | Date: | Thu, 20 Sep 2018 21:08:28 +0000 |
| Subject: | Bug #76909 [Opn]: preg_match difference between 7.3 and < 7.3 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217161@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76909&edit=1
ID: 76909
Updated by: requinix@php.net
Reported by: jay at diablomedia dot com
Summary: preg_match difference between 7.3 and < 7.3
Status: Open
Type: Bug
Package: *Regular Expressions
Operating System: Linux
PHP Version: 7.3.0RC1
Block user comment: N
Private report: N
New Comment:
Looks like a PCRE bug because turning off JIT makes it work correctly again. So that's the
workaround.
ini_set("pcre.jit", 0);
PHP 7.3 is currently bundling PCRE 10.31. Version 10.32-RC1 includes a fix for something that looks
related.
> 35. In a pattern such as /[^\x{100}-\x{ffff}]*[\x80-\xff]/ which has a repeated
> negative class with no characters less than 0x100 followed by a positive class
> with only characters less than 0x100, the first class was incorrectly being
> auto-possessified, causing incorrect match failures.
https://www.pcre.org/changelog.txt
https://bugs.exim.org/show_bug.cgi?id=2300
While your example doesn't have the negated set, the fix for the bug was very simple so it
could affect less complicated situations like yours as well.
Previous Comments:
------------------------------------------------------------------------
[2018-09-20 20:41:37] jay at diablomedia dot com
Description:
------------
I was testing a fork of Zend Framework 1 that we maintain for our legacy applications against php
7.3.0rc1 and noticed the Zend_Validate component's tests were failing on php 7.3: https://travis-ci.org/diablomedia/zf1-validate/jobs/431170057
In this case, php 7.3 is allowing some hostnames through validation that are being rejected in php
< 7.3.
I dug a bit, and was able to reproduce this with a single regular expression that is evaluated
differently in php 7.3 than it is in php 5.6 through php 7.2.
Here's a link to 3v4l.org demonstrating the difference (script is in the "Test
script" section of this report): https://3v4l.org/DR3S5
Test script:
---------------
<?php
$domainPart = ' domain.com';
$regexChar = '/^[\x{0100}-\x{017f}]{1,63}$/iu';
preg_match($regexChar, $domainPart, $matches);
print_r($matches);
Expected result:
----------------
I would expect the $matches array in the test script to be empty here, similar to all PHP versions
before 7.3.
Actual result:
--------------
The regex matches on " domain.com", which it doesn't in earlier versions of PHP.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76909&edit=1