You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The xml method does not behave as I would expect as it modifies the hash that is passed into it. Moreover, it modifies elements within the hash as it proceeds. Consider the following code:
Note that the xs1:nil attribute is not set in the XML when it should be. This is because somehow Gyoku is modifying the content of the nil_content variable.
By changing the bar_xml assignment to use the Rails deep_dup() Hash method to:
bar_xml = Gyoku.xml(bar.deep_dup)
puts bar_xml
This produces:
I note that in the implementation it performs a dup on the hash that is called, but that is insufficient. It should perform (the equivalent) a deep_dup instead.
The text was updated successfully, but these errors were encountered:
Thanks for catching this @mcclumpherty. I can only wonder how many people were bit by this bug before and never spoke up about it. Is this something you'd be interested in submitting a pull request for?
On reflection, I wonder if a deep_dup is a bit of a cheap and nasty solution. Not having looked through the implementation in detail, I wonder why the hash is being modified in the first place. Maybe the right solution would be not to do that. I'll have a think about submitting a pull request when I get the time.
I suspect the cause is that ruby objects are always passed by reference and the call to #dup doesn't recurse into the hash's keys and values. I'd consider using @balmma's ruby_deep_clone gem for this behavior, although there might be something better. ruby_deep_clone seems to be fairly performant.
The xml method does not behave as I would expect as it modifies the hash that is passed into it. Moreover, it modifies elements within the hash as it proceeds. Consider the following code:
nil_content = { :content! => nil, :'@xs1:nil' => 1 }
bar = { request: { "attributes" => { "text" => nil_content, "date" => nil_content } }}
bar_xml = Gyoku.xml(bar)
puts bar_xml
This produces:
Note that the xs1:nil attribute is not set in the XML when it should be. This is because somehow Gyoku is modifying the content of the nil_content variable.
By changing the bar_xml assignment to use the Rails deep_dup() Hash method to:
bar_xml = Gyoku.xml(bar.deep_dup)
puts bar_xml
This produces:
I note that in the implementation it performs a dup on the hash that is called, but that is insufficient. It should perform (the equivalent) a deep_dup instead.
The text was updated successfully, but these errors were encountered: