rurban / Cpanel-JSON-XS

Improved fork of JSON-XS

Home Page:http://search.cpan.org/dist/Cpanel-JSON-XS/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

decode_json( '"string"', 0 ); works despite documentation

plicease opened this issue · comments

I think technically the documentation is correct?

If the new optional $allow_nonref argument is set and not false, the allow_nonref option will be set and the function will act is described as in the relaxed RFC 7159 allowing all values such as objects, arrays, strings, numbers, "null", "true", and "false".

Since it does not explicitly say what happens if $allow_nonref is set but false, but it does suggest that it will use the default behavior?

  DB<102> x Cpanel::JSON::XS::decode_json('"string"', 0);
0  'string'
  DB<103> x Cpanel::JSON::XS::decode_json('"string"', undef);
0  'string'

This is definitely a bug, setting it false explicitly should cause that to error

The problem is here:

if (ix && allow_nonref)

the code is checking for whether the argument is NULL instead of a non-NULL and true.

Oops, I'm embarrassed. Did I write that nonsense? Sorry.

Fixed in 4.24