diff options
author | Christian Schneider | 2025-03-25 03:15:58 +0100 |
---|---|---|
committer | Christian Schneider | 2025-03-25 03:15:58 +0100 |
commit | 470fef0c3b772bf24ed161641ae9d2bd92fac4fa (patch) | |
tree | 33cec41d07fb7e7bbbbc8988e498cc740f2f1ce5 | |
parent | d713c9103aaeffdcf47f5ce73e2c75dac4f1b76b (diff) | |
download | itools-470fef0c3b772bf24ed161641ae9d2bd92fac4fa.tar.gz itools-470fef0c3b772bf24ed161641ae9d2bd92fac4fa.tar.bz2 itools-470fef0c3b772bf24ed161641ae9d2bd92fac4fa.zip |
Handle pretty printed null including newlines in it::json_decode
-rw-r--r-- | it.class | 2 | ||||
-rwxr-xr-x | test/it.t | 1 |
2 files changed, 2 insertions, 1 deletions
@@ -1263,7 +1263,7 @@ static function json_encode($data, $p = []) */ static function json_decode($json, $p = []) { - return ($data = json_decode($json, $p['assoc'])) === null && $json != 'null' ? it::error((array)$p['it_error'] + ['title' => "invalid json", 'body' => $json]) : $data; + return ($data = json_decode($json, $p['assoc'])) === null && trim($json) != 'null' ? it::error((array)$p['it_error'] + ['title' => "invalid json", 'body' => $json]) : $data; } /** @@ -481,6 +481,7 @@ foreach ([$dummy, false, true, null, 1, "a", "Ä", "/", []] as $var) is(it::json_decode(it::json_encode($var)), $var); is(it::json_decode('{"foo":"bar"}')->foo, "bar"); is(it::json_decode('{"foo":"bar"}', ['assoc' => true])['foo'], "bar"); +is(it::json_decode("\nnull\n\n", ['it_error' => ['fatal' => true]]), null, 'json_decode pretty printed null value'); is(it::cdist(null), true); is(it::cdist(), true); |