php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70037 PCRE_DOLLAR_ENDONLY fails on newlines when used with pipe operator
Submitted: 2015-07-09 23:29 UTC Modified: 2015-07-10 03:46 UTC
From: chrisdmiddleton at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.6.10 OS: Mac OS X 10.9.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chrisdmiddleton at gmail dot com
New email:
PHP Version: OS:

 

 [2015-07-09 23:29 UTC] chrisdmiddleton at gmail dot com
Description:
------------
When trying to match newlines with the PCRE_DOLLAR_ENDONLY modifier in conjunction with the "|" operator, it matches more than it should.

My original test case was using a regex of '/^\n|\r\n|\r$/D' against a string containing other characters. I've simplified the test below.

Test script:
---------------
echo preg_match('/^\n|\n$/D', "\nasdf", $matches);

Expected result:
----------------
0

Actual result:
--------------
1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-10 01:47 UTC] keithm at aoeex dot com
The given test case is performing as expected.  It matches on the ^\n branch of the regular expression.

/^\n|\n$/D means: Match start-of-input followed by a new-line OR a new-line followed by end-of-input.
 [2015-07-10 03:46 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-07-10 03:46 UTC] requinix@php.net
Yup.
 [2015-07-10 04:23 UTC] chrisdmiddleton at gmail dot com
Whoops - you're complete right. Sorry for the false alarm. I've been bitten by regex operator precedence before - hopefully this will be the last time. Thanks for pointing out my error.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 10:01:31 2024 UTC