php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52172 Impossible to escape escape character
Submitted: 2010-06-24 16:35 UTC Modified: 2010-06-24 17:00 UTC
From: harald dot lapp at gmail dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.3.2 OS: *
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: harald dot lapp at gmail dot com
New email:
PHP Version: OS:

 

 [2010-06-24 16:35 UTC] harald dot lapp at gmail dot com
Description:
------------
Apparently it's impossible to decode strings with escaped "escape" character: 

\\

this should work however, as it's written in the json specs on http://json.org/

Test script:
---------------
<?php

var_dump(json_decode('["\\"]', true));

?>

Expected result:
----------------
array(1) {
  [0]=>
  string(1) "\"
}

Actual result:
--------------
NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-24 16:51 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-06-24 16:51 UTC] rasmus@php.net
You are confusing PHP escapes and json escapes.

Watch:

php > $str = '["\\"]';
php > echo $str;
["\"]

That's obviously not valid json.  What you actually want:


php > $str = '["\\\\"]';
php > echo $str;
["\\"]
php > var_dump(json_decode($str));
array(1) {
  [0]=>
  string(1) "\"
}

Works fine.  No bug here.
 [2010-06-24 17:00 UTC] harald dot lapp at gmail dot com
you are right, of course -- i got confused. sorry for reporting and thanks for fast reply!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 19:01:37 2025 UTC