Bug #49323 [Com]: json_decode escaped character weirdness

[email protected] ("dmitry dot dulepov at gmail dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at http://bugs.php.net/bug.php?id=49323&edit=1

 ID:               49323
 Comment by:       dmitry dot dulepov at gmail dot com
 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:

I appologize. The problem was elsewhere. Sorry for the trouble.


Previous Comments:
------------------------------------------------------------------------
[2010-03-25 13:58:12] paul dot wieland at port80ware dot com

It definitely works just fine in FireFox. The entire project I was
working on 
(which prompted this bug post) was tested with FF and everything worked
fine.

------------------------------------------------------------------------
[2010-03-25 13:51:23] [email protected]

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.

------------------------------------------------------------------------
[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] [email protected]

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

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


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