Edit report at http://bugs.php.net/bug.php?id=49323&edit=1
ID: 49323
Updated by: [email protected]
Reported by: paul dot wieland at port80ware dot com
Summary: json_decode escaped character weirdness
Status: Bogus
Type: Bug
Package: JSON related
Operating System: Linux / OSX
PHP Version: 5.3.0
New Comment:
dmitry, I don't understand your last comment. Of course / is escaped in
the
json encoded string. According to the spec it is supposed to be. The
important
part is that when you json_decode() it it comes back without the \ which
it
does:
> php -v
PHP 5.3.3-dev (cli) (built: Feb 10 2010 10:53:36)
> php -a
php > $enc = json_encode(array('test' => 'hello/world'));
php > echo $enc;
{"test":"hello\/world"}
php > var_dump(json_decode($enc));
object(stdClass)#1 (1) {
["test"]=>
string(11) "hello/world"
}
Previous Comments:
------------------------------------------------------------------------
[2010-03-25 12:49:26] dmitry dot dulepov at gmail dot com
No, it is definitely NOT fixed.
php -v says:
=================
PHP 5.3.1 (cli) (built: Feb 15 2010 17:30:23)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
=================
Test file:
=================
<?= json_encode(array('test' => 'hello/world')) . chr(10);
=================
Result:
=================
{"test":"hello\/world"}
=================
------------------------------------------------------------------------
[2009-08-22 10:11:12] [email protected]
Definitely fixed in 5.3
scott-mbp:~ scott$ php /tmp/test.php
string(10) "Black/Gray"
string(10) "Black/Gray"
------------------------------------------------------------------------
[2009-08-21 19:35:42] paul dot wieland at port80ware dot com
Very sorry, the virtualhost I was using was not configured to use
version 5.3.0 - it is using 5.2.1 instead
So I am not sure if this is an old problem with 5.2.1 that has been
solved, or it still exists with 5.3.0
------------------------------------------------------------------------
[2009-08-21 19:31:12] paul dot wieland at port80ware dot com
Description:
------------
json_encode is not removing the backslash from escaped forward slashes
in my strings. It works fine on several machines running 5.2.x, but on
one new machine running php 5.3.0 it returns the wrong result.
Reproduce code:
---------------
$my_string = 'Black/Gray';
var_dump($my_string);
var_dump(
json_decode(
json_encode($my_string)
)
);
Expected result:
----------------
string(10) "Black/Gray"
string(10) "Black/Gray"
Actual result:
--------------
string(10) "Black/Gray"
string(11) "Black\/Gray"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=49323&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.