-
Notifications
You must be signed in to change notification settings - Fork 340
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
Optimize Symbol generation in strict mode #745
Conversation
b3a8d5b
to
a43983e
Compare
a43983e
to
1bb591e
Compare
1bb591e
to
8e0f3b7
Compare
50a87ba
to
4e2078a
Compare
test/json/json_generator_test.rb
Outdated
@@ -86,6 +86,9 @@ def test_dump_strict | |||
|
|||
assert_equal '42', dump(42, strict: true) | |||
assert_equal 'true', dump(true, strict: true) | |||
|
|||
assert_equal '"hello"', dump(:hello, strict: true) | |||
assert_equal '"World"', dump("World".to_sym, strict: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should test that to_json
is not called with strict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's somewhat already asserting that because json/add/symbol
is loaded in the test suite.
4e2078a
to
d8b0960
Compare
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
d8b0960
to
d37638e
Compare
FWIW I realized this means |
I think that ship has sailed when symbols were accepted as hash keys regardless. But yes, we could chose to do the opposite and reject them in strict mode. One goal of |
In strict mode we don't need to check for
to_json
, we can just generate a String from a Symbol.It changes behavior because previously Symbol caused a generator error. But keys in hashes already had support for automatic coercion to String, so it feels ok to do.