Bug #75746 [NEW]: empty string is (wrongly) accepted as valid json
| From: | php at richardneill dot org | Date: | Sat, 30 Dec 2017 00:51:14 +0000 |
| Subject: | Bug #75746 [NEW]: empty string is (wrongly) accepted as valid json | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213322@lists.php.net to get a copy of this message | ||
From: php at richardneill dot org
Operating system: Linux
PHP version: 7.2.0
Package: JSON related
Bug Type: Bug
Bug description:empty string is (wrongly) accepted as valid json
Description:
------------
In order to validate whether a given string is legitimate JSON, the
documentation at: http://php.net/manual/en/function.json-decode.php
suggests that we run it through json_decode() and then check that
json_last_error() is JSON_ERROR_NONE.
However, when the string is empty, json_last_error() is not set.
The empty string is not syntactically valid as json.
Test script:
---------------
$checkme = '';
json_decode($checkme);
if (json_last_error() === JSON_ERROR_NONE){
echo "OK";
}else{
echo "FAIL";
}
#This should result in "FAIL",
#but it gives "OK", wrongly imho.
Expected result:
----------------
json_decode('');
should set json_last_error().
Actual result:
--------------
[Note: this seems to be very similar to the same issue in bugs 54484 and
68938, both of which were fixed and closed on the PHP 5 series]
--
Edit bug report at https://bugs.php.net/bug.php?id=75746&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75746&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75746&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75746&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75746&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75746&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75746&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75746&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75746&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75746&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75746&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75746&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75746&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75746&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75746&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75746&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75746&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75746&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75746&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75746&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75746&r=mysqlcfg