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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC