php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42186 json_decode() won't work with \l
Submitted: 2007-08-02 18:47 UTC Modified: 2007-08-05 16:33 UTC
From: djlopez at gmx dot de Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.2.3 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: djlopez at gmx dot de
New email:
PHP Version: OS:

 

 [2007-08-02 18:47 UTC] djlopez at gmx dot de
Description:
------------
json_decode() returns nothing, when the string contains an \l (lowercase L), maybe (internal) crash!?

Reproduce code:
---------------
$json = '{"stringwithbreak":"line with a \lbreak!"}';
print_r(json_decode($json, true));


Expected result:
----------------
print_r() is NOT returning anything, json_decode() seems to be not executed.

Actual result:
--------------
Could be "solved" this way:

print_r(json_decode(str_replace("\\l", "", $json), true));
However, it's a bug...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-04 14:17 UTC] jani@php.net
Replace print_r() with var_dump() and you might actually see something.

 [2007-08-04 14:24 UTC] jani@php.net
And according to http://www.json.org/ \l is not in the accepted list of chars. So no bug here.

 [2007-08-04 14:42 UTC] djlopez at gmx dot de
I want to remember you, where JSON is used: Javascript - to send data to the server.

When there's a textarea, some OS/Browser are sending an \l for a linebreak. So, if an \l is into the string, the _whole_ function won't work! Sometimes it also appears with an \n, but I can't reproduce this error. Maybe it has multiple causes.

And as far as I can see, there's no thrown exception to catch this error. The function json_decode() may be implemented very strictly, but without an exception, it's very hard to debug the code. 

Please DON'T set this bug to closed!!! Don't ignore the not-that-good implementation! Thx!
 [2007-08-05 15:18 UTC] djlopez at gmx dot de
Another "bug":

$json = '{"titel":"Trance","desc":"Trance%0ADJ"}';
var_dump(json_decode(urldecode($json), true));


Afaik %0A is urlencoded for \n. 
json_decode() is returning NULL here also! And this should be a bug...
 [2007-08-05 16:33 UTC] scottmac@php.net
Thats to be expected.

Newlines need to be escaped as it reads on http://www.json.org/ you can also read that \l isn't valid.

The grammar is available at http://www.ietf.org/rfc/rfc4627.txt under Strings if you want a better read.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC