Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Gyoku.xml() method is not idempotent #40

@mcclumpherty

Description

@mcclumpherty

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions