flori / json

JSON implementation for Ruby
https://flori.github.io/json
Other
669 stars 322 forks source link

strict option is broken for pure-Ruby implementation #584

Open eregon opened 4 months ago

eregon commented 4 months ago

In this repo:

$ bundle exec ruby -rjson/pure -e 'p JSON.dump({"a" => 1}, strict: true)'
/home/eregon/code/json/lib/json/pure/generator.rb:358:in `block in json_transform': Integer not allowed in JSON (JSON::GeneratorError)
    from /home/eregon/code/json/lib/json/pure/generator.rb:353:in `each'
    from /home/eregon/code/json/lib/json/pure/generator.rb:353:in `json_transform'
    from /home/eregon/code/json/lib/json/pure/generator.rb:337:in `to_json'
    from /home/eregon/code/json/lib/json/pure/generator.rb:289:in `generate'
    from /home/eregon/code/json/lib/json/common.rb:306:in `generate'
    from /home/eregon/code/json/lib/json/common.rb:627:in `dump'
    from -e:1:in `<main>'

But of course Integer should be allowed.

The bug seems clear when looking at https://github.com/flori/json/blob/4f876a8bf7c45972800bae5bdbaf892aa2f714a5/lib/json/pure/generator.rb#L357-L363 https://github.com/flori/json/blob/4f876a8bf7c45972800bae5bdbaf892aa2f714a5/lib/json/pure/generator.rb#L400-L406

It was added in https://github.com/flori/json/pull/519 but with too few tests so they didn't catch this bug. @byroot / @casperisfine Could you fix this?

casperisfine commented 4 months ago

https://github.com/flori/json/pull/585