cloocher / xmlhasher

Fast XML to Ruby Hash converter
MIT License
40 stars 20 forks source link

Bug: string_keys only works if another option is also specified #24

Closed fernandomm closed 4 years ago

fernandomm commented 4 years ago

string_keys: true only works if another option is specified.

[1] pry(main)> xml = %(<my-tag><MyTag2>content</MyTag2></my-tag>)
=> "<my-tag><MyTag2>content</MyTag2></my-tag>"

[2] pry(main)> XmlHasher::Parser.new({ string_keys: true }).parse(xml)
=> {:"my-tag"=>{:MyTag2=>"content"}}

[3] pry(main)> XmlHasher::Parser.new({ string_keys: true, snakecase: true }).parse(xml)
=> {"my_tag"=>{"my_tag2"=>"content"}}

Looks like name is always a symbol in https://github.com/cloocher/xmlhasher/blob/f4b3908789b8eba0f1c6621a4cdb53982352fd60/lib/xmlhasher/handler.rb#L50

So maybe to_sym should be to_s and unless changed to if in https://github.com/cloocher/xmlhasher/blob/f4b3908789b8eba0f1c6621a4cdb53982352fd60/lib/xmlhasher/handler.rb#L54