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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 - 22 = ?
Subscribe to this entry?

 
 [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: Mon May 06 19:01:32 2024 UTC