#45989 [Opn->Bgs]: json_decode() passes through certain invalid JSON strings
| From: | iliaa@php.net | Date: | Wed, 10 Sep 2008 00:38:10 +0000 |
| Subject: | #45989 [Opn->Bgs]: json_decode() passes through certain invalid JSON strings | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-128826@lists.php.net to get a copy of this message | ||
ID: 45989
Updated by: iliaa@php.net
Reported By: steven at acko dot net
-Status: Open
+Status: Bogus
Bug Type: JSON related
Operating System: Mac OS X
PHP Version: 5.2.6
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
.
Previous Comments:
------------------------------------------------------------------------
[2008-09-04 00:32:20] steven at acko dot net
Description:
------------
When json_decode() is given certain invalid JSON strings, it will
return
the literal string as the result, rather than returning NULL.
Note: in #38680, the decision was made to allow json_decode() to accept
literal basic types (strings, ints, ...) even though this is not
allowed
by RFC 4627 (which only allows objects/arrays). This bug report is
different because even under the PHP interpretation of JSON, these
strings can not be considered valid, and trivial variations on them do
in fact throw an error as expected.
(The non-standard behaviour introduced in #38680 is not documented at
all by the way, which is kind of ironic given the numerous issues that
have 'go read the spec' as the answer)
Reproduce code:
---------------
var_dump(json_decode("'invalid json'"));
var_dump(json_decode('invalid json'));
var_dump(json_decode(' {'));
var_dump(json_decode(' ['));
Expected result:
----------------
NULL
NULL
NULL
NULL
Actual result:
--------------
string(14) "'invalid json'"
string(12) "invalid json"
string(2) " {"
string(2) " ["
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45989&edit=1