Closed pavelsr closed 4 years ago
Same problem if decode_json('')
The current behavior seems correct to me.
Mojo::JSON
implements RFC-8259
in which you can see the JSON Grammar being defined as follows:
JSON-text = ws value ws
[...]
ws = *(
%x20 / ; Space
%x09 / ; Horizontal tab
%x0A / ; Line feed or New line
%x0D ) ; Carriage return
[...]
value = false / null / true / object / array / number / string
[...]
false = %x66.61.6c.73.65 ; false
null = %x6e.75.6c.6c ; null
[...]
string = quotation-mark *char quotation-mark
This means that an empty string is not valid JSON, it needs at the very least some quotation marks inside
If you think you might have an empty value instead of valid JSON, you can easily check length $json
before attempting to decode.
If it's a bug, it would be with the backend that is being used (Cpanel::JSON::XS in most cases, unless you twiddled some environment variables -- see the Mojo::JSON source, as it's not long).
Steps to reproduce the behavior
Expected behavior
I think
decode_json
must return undefActual behavior
decode_json
dies