#42708 [Opn]: json_decode: escape characters

From: Date: Fri, 23 Nov 2007 00:45:21 +0000
Subject: #42708 [Opn]: json_decode: escape characters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-119972@lists.php.net to get a copy of this message
 ID:          42708
 Updated by:  felipe@php.net
 Reported By: tjerk dot meesters at muvee dot com
 Status:      Open
 Bug Type:    JSON related
 PHP Version: 5.2.4
 New Comment:

php5.3-200711221930:

string(22) "Sir, you\'re an idiot!"
NULL
--

php6.0-200711202130:

string(22) "Sir, you\'re an idiot!"
string(26) "["Sir, you\'re an idiot!"]"


Previous Comments:
------------------------------------------------------------------------

[2007-09-19 10:19:22] tjerk dot meesters at muvee dot com

Description:
------------
When a single quote is being escaped, the json_decode() gives some
unexpected results.

1. According to the JSON specs, the single quote is not in the list of
characters that can follow the escape character (such as n, t, b, r,
etc.); however, JavaScript does recognize the single quote so it would
be very nice to have as a feature.

2. When wrapping a string with an escaped single quote inside an array
context, the json_decode() gives up and returns NULL.

Reproduce code:
---------------
<?php

$s = '"Sir, you\\\'re an idiot!"';
var_dump(json_decode($s));
var_dump(json_decode("[$s]"));

?>


Expected result:
----------------
string(21) "Sir, you're an idiot!"
array(1) {
  [0]=>
  string(21) "Sir, you're an idiot!"
}

Actual result:
--------------
string(22) "Sir, you\'re an idiot!"
NULL



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42708&edit=1


Thread (3 messages)

« previous php.bugs (#119972) next »