You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"true" (or "false") in decode("true") or decode_json("true") is not a reference, and therefore needs to fail.
decode needs allow_nonref to pass. At least my understanding is that true/false are no JSON objects, they are a primitive. Even "null" is not a valid JSON text/object.
$json->allow_nonref ([$enable])
If $enable is true (or missing), then the encode method can convert a
non-reference into its corresponding string, number or null JSON value,
which is an extension to RFC4627. Likewise, decode will accept those JSON
values instead of croaking.
If $enable is false, then the encode method will croak if it isn't
passed an arrayref or hashref, as JSON texts must either be an object
or array. Likewise, decode will croak if given something that is not a
JSON object or array.
A JSON text is a sequence of tokens. The set of tokens includes six
structural characters, strings, numbers, and three literal names.
A JSON text is a serialized object or array.
JSON-text = object / array
[...]
2.1. Values
A JSON value MUST be an object, array, number, or string, or one of
the following three literal names:
false null true
So the literal names are no objects. They are valid JSON values, but not a valid JSON text.
This is wrong in all perl JSON packages, but correct in ruby. php json_decode extends rfc4627 as our allow_nonref flags by allowing null, true and false.
Interestingly the JSON::XS documentation and error message is spec conformant, just the implementation not. => decode_json("false")
JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)
Changing the XS internal true/false SV from RV to the direct blessed object of JSON::PP::Boolean fixes this bug, and also enables eq overload.
previously we used a RV to the blessed PVMG JSON::PP::Boolean object.
The problem is with eq overloading, that eq needs the object directly,
it will not call overload magic on the reference < 5.16
I work on this in the branch nonrefbool-gh41 but a whole lot of hell broke loose with this change.
Maybe just disable eq overload and keep the 3.0115 state.
The text was updated successfully, but these errors were encountered:
overload is broken <5.18. use schmorps workaround.
stringify false to "0" to stay false, but true to "true".
change the XS true/false from RV to PVMG. stricter!
Previously we used a RV to the blessed PVMG JSON::PP::Boolean object.
The problem is with eq overloading, that eq needs the object directly,
it will not call overload magic on the reference < 5.16
As sideeffect this made decode("true") stricter.
We need now ->allow_nonref->decode("true").
Also decode_json("true") will now fail as decode_json does not
enable allow_nonref.
This is a regression from JSON::XS and older Cpanel::JSON::XS releases, but
works as documented.
See GH #41
Implemented the stricter and consistent decode_json option now in master.
The error message was always there, it was just not used due to a JSON::XS bug.
"true" (or "false") in decode("true") or decode_json("true") is not a reference, and therefore needs to fail.
decode needs allow_nonref to pass. At least my understanding is that true/false are no JSON objects, they are a primitive. Even "null" is not a valid JSON text/object.
Confirmed by the spec http://www.ietf.org/rfc/rfc4627.txt
So the literal names are no objects. They are valid JSON values, but not a valid JSON text.
This is wrong in all perl JSON packages, but correct in ruby. php json_decode extends rfc4627 as our allow_nonref flags by allowing null, true and false.
Interestingly the JSON::XS documentation and error message is spec conformant, just the implementation not. => decode_json("false")
JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)
Changing the XS internal true/false SV from RV to the direct blessed object of JSON::PP::Boolean fixes this bug, and also enables eq overload.
previously we used a RV to the blessed PVMG JSON::PP::Boolean object.
The problem is with eq overloading, that eq needs the object directly,
it will not call overload magic on the reference < 5.16
I work on this in the branch
nonrefbool-gh41but a whole lot of hell broke loose with this change.Maybe just disable eq overload and keep the 3.0115 state.
The text was updated successfully, but these errors were encountered: