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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 15:01:28 2019 UTC