Skip to content

strict option is broken for pure-Ruby implementation #584

@eregon

Description

@eregon

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 #519 but with too few tests so they didn't catch this bug.
@byroot / @casperisfine Could you fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions