Bug #74675 [Com]: Regex that worked fine on 5.x Fails Randomly on 7.x
| From: | donatj at gmail dot com | Date: | Tue, 30 May 2017 21:37:48 +0000 |
| Subject: | Bug #74675 [Com]: Regex that worked fine on 5.x Fails Randomly on 7.x | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209306@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74675&edit=1
ID: 74675
Comment by: donatj at gmail dot com
Reported by: donatj at gmail dot com
Summary: Regex that worked fine on 5.x Fails Randomly on 7.x
Status: Not a bug
Type: Bug
Package: PCRE related
Operating System: Darwin / Linux
PHP Version: 7.1.5
Block user comment: N
Private report: N
New Comment:
Your solution regex while working on the specific input actually fails on more of my inputs than the
original. Sigh. I'll accept the "not a bug" verdict but I'm not happy about the
JIT's seemingly uselessness at all.
Previous Comments:
------------------------------------------------------------------------
[2017-05-30 20:41:35] requinix@php.net
PHP 7 introduced PCRE's JIT feature. When enabled this changes how regexes are compiled and
executed.
http://sljit.sourceforge.net/pcre.html
preg_last_error() is returning PREG_JIT_STACKLIMIT_ERROR which means what it sounds like it means
and is caused by an inefficient regex.
If I alter your regex a bit by tweaking the backslash treatment and adding +s
'/(?(?=")"(\\\\.|[^\\\\"]+)*"|\'(\\\\.|[^\\\\\']+)*\')/'
then it executes fine on the test string (and also fixes what I assume was a bug with the original).
------------------------------------------------------------------------
[2017-05-30 20:14:56] donatj at gmail dot com
Description:
------------
We use this regex (?(?=")"(\\"|[^"])*"|'(\\'|[^'])*')
as part of our internal CI system as a step to clear strings.
We were getting weird failures on 7.x builds and I hunted it down to the fact that this regex
randomly fails on some strings in 7.x. It works in most cases, but we have 4 files where it
randomly fails and returns NULL.
It's worked fine prior in 5.x for years, and works on HHVM fine so something must have changed
in PHP7.
Test script:
---------------
The issue can be seen here. https://3v4l.org/SEWZc / https://gist.github.com/donatj/b872de5cc8f755871500a82c483aa92f
I boiled the input string down as much as I could manage, it's still very long.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74675&edit=1