-
Notifications
You must be signed in to change notification settings - Fork 205
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
Fix custom marshalization with symbolize_names: true #476
Conversation
jruby failures seem unrelated. |
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.
Thanks for the fast response!
lib/psych/visitors/to_ruby.rb
Outdated
@@ -366,7 +366,7 @@ def revive_hash hash, o | |||
hash[key] = val | |||
end | |||
else | |||
if @symbolize_names | |||
if !force_string_keys && @symbolize_names |
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.
force_string_keys
is a misleading name. If you have a YAML doc that has Symbols, Numerics, Booleans, etc, as keys then setting force_string_keys = true
passes those through without modification, it doesn't force them to be strings, it just skips the #to_sym
call.
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.
Yes, I wasn't very insprired at that time, I think I'll rename it to tagged
or something.
What's the use case for combining custom If you have an untyped/untagged document, and you're using YAML as a JSON replacement, But if you do have custom Behavior like this?: doc = <<~YAML
---
baz: !ruby/object:Foo
bar: 42
YAML
p Psych.load(doc)
# {"baz"=>#<Foo:0x000056141892d218 @bar=42>}
p Psych.load(doc, symbolize_names: true)
# {:baz=>#<Foo:0x0000561418cefe00 @bar=42>} Using doc = <<~YAML
---
:baz: !ruby/object:Foo
bar: 42
YAML
p Psych.load(doc)
# {:baz=>#<Foo:0x0000561418cefe00 @bar=42>} |
Yes, and that was the behavior up to Psych 3.1.0, this PR fixes a regression. |
b300d87
to
ee26f26
Compare
Reported to me by @peterthesling.
Repo script
What happens is that the Hash built to be passed to
init_with
get its keys symbolized, which breaks theinit_with
.cc @tenderlove