Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strict option is broken for pure-Ruby implementation #584

Closed
eregon opened this issue May 9, 2024 · 1 comment · Fixed by #585
Closed

strict option is broken for pure-Ruby implementation #584

eregon opened this issue May 9, 2024 · 1 comment · Fixed by #585

Comments

@eregon
Copy link
Member

eregon commented May 9, 2024

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?

casperisfine pushed a commit to casperisfine/json that referenced this issue May 9, 2024
@casperisfine
Copy link

#585

casperisfine pushed a commit to casperisfine/json that referenced this issue May 9, 2024
casperisfine pushed a commit to casperisfine/json that referenced this issue May 9, 2024
@byroot byroot closed this as completed in 3652866 Oct 8, 2024
hsbt pushed a commit to hsbt/ruby that referenced this issue Oct 8, 2024
hsbt pushed a commit to ruby/ruby that referenced this issue Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants