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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: celebgolfer at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sat Dec 21 14:01:32 2024 UTC