ruby / json

JSON implementation for Ruby
https://ruby.github.io/json
Other
705 stars 332 forks source link

Add tests for the behavior of JSON.generate with base types subclasses #679

Closed casperisfine closed 3 weeks ago

casperisfine commented 3 weeks ago

Ref: https://github.com/ruby/json/pull/674 Ref: https://github.com/ruby/json/pull/668

The behavior on such case it quite unclear, the goal here is to figure out whatever was the behavior on Cext version of json 2.7.0 and get all implementations to converge.

We can then decide to make them all behave differently if we so wish.

FYI: @eregon

eregon commented 3 weeks ago

For the ActiveSupport use case in https://github.com/ruby/json/issues/667 maybe this extra escaping should/could be a JSON.dump option? Then maybe we wouldn't need to treat subclasses any specially. Or EscapedString wouldn't inherit from String, seems even simpler/clearer.

casperisfine commented 3 weeks ago

I created a self contained test case to more easily test historical behavior, and it seems we already diverged: https://gist.github.com/casperisfine/a379245862b0d5273086e5053657460a

I'll update the test suite to have the same behavior as 2.7.2