php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52914 preg_replace() e-modificator bug
Submitted: 2010-09-23 16:49 UTC Modified: 2010-09-24 05:30 UTC
From: celebgolfer at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.3 OS: Windows 7 & FreeBSD 7.2
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:
18 + 13 = ?
Subscribe to this entry?

 
 [2010-09-23 16:49 UTC] celebgolfer at gmail dot com
Description:
------------
preg_replace() add slashes to double quotes arbitarily.

Test script:
---------------
echo preg_replace("/(\".*\")/e","'[\\1]'",'"1\"\n2"');

Expected result:
----------------
["1\"\n2"]

Actual result:
--------------
[\"1\\"\n2\"]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-24 05:30 UTC] aharvey@php.net
-Status: Open +Status: Bogus -Package: Scripting Engine problem +Package: PCRE related
 [2010-09-24 05:30 UTC] aharvey@php.net
This is documented behaviour. Quoting the manual at
http://au2.php.net/manual/en/reference.pcre.pattern.modifiers.php :


e (PREG_REPLACE_EVAL)

If this modifier is set, preg_replace() does normal substitution of backreferences in the replacement string, evaluates it as PHP code, and uses the result for replacing the search string. Single quotes, double quotes, backslashes (\) and NULL chars will be escaped by backslashes in substituted backreferences.


Note the section about quotes being escaped by backslashes.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 21:01:33 2024 UTC