Bug #49323 [Bgs]: json_decode escaped character weirdness

From: Date: Thu, 25 Mar 2010 12:51:23 +0000
Subject: Bug #49323 [Bgs]: json_decode escaped character weirdness
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-149003@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=49323&edit=1

 ID:               49323
 Updated by:       rasmus@php.net
 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:

No, I wouldn't suggest you do that.  It works perfectly fine in Firefox.
 Check 
your own code.  I wrote a quick check to make sure it works in FF. 
Point your 
browser at:

http://progphp.com/test.html

Then do a view-source to see what I am doing.


Previous Comments:
------------------------------------------------------------------------
[2010-03-25 13:35:00] dmitry dot dulepov at gmail dot com

Ok, I see the point... However FireFox does not like that escaping. So
any AJAX 
applications that use this generated JSON do not work in FireFox. It is
enough to 
have \/ in JSON to cause JavaScript error in FireFox. Should I report
the bug to 
FireFox than?

------------------------------------------------------------------------
[2010-03-25 13:22:46] rasmus@php.net

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"
}

------------------------------------------------------------------------
[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] scottmac@php.net

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

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=49323


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


Thread (9 messages)

« previous php.bugs (#149003) next »