Skip to content
This repository

Fix for Lighthouse ticket # 6334 : to_xml should render valid xml or raise an error all the time #445

merged 1 commit into from almost 3 years ago

3 participants

Prakash Murthy José Valim Aaron Patterson
Prakash Murthy

Raise a RuntimeException with custom message when hash key contains space. Old behavior was { "New York"=>33, :Versailles => 3231 }.to_xml created an xml which was invalid.

José Valim

Shouldn't we just dasherize the keys or something like that?

Aaron Patterson

@josevalim I agree. @prakashmurthy, can you change this to dasherize keys, and I'll apply?

Prakash Murthy

Since dasherize method only replaces '_' with '-', and does not do anything to spaces, we are thinking of using gsub(' ','-').Is this OK?

Prakash Murthy

Used gsub instead of _dasherize method as there is another issue with _dasherize method being broken. #450

José Valim

Thanks @prakashmurthy! I have fixed the _dasherize method, do you think your pull request could be refactored then? As the default is to dasherize, I don't even think we need to do anything, just add your tests. Could you please check?

Prakash Murthy

Thanks @josevalim. Refactored the code; now the change includes only the tests. Let me know if anything else needs to be done.

Aaron Patterson tenderlove merged commit a45f300 into from May 08, 2011
Aaron Patterson tenderlove closed this May 08, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 08, 2011
Prakash Murthy Lighthouse ticket # 6334; added tests to verify that spaces in key ar…
…e dasherized.
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 10 additions and 0 deletions. Show diff stats Hide diff stats

  1. 10  activesupport/test/xml_mini_test.rb
10  activesupport/test/xml_mini_test.rb
@@ -87,6 +87,16 @@ def to_xml(options) options[:builder].yo(options[:root].to_s) end
87 87
       @xml.to_tag(:b, "Howdy", @options)
88 88
       assert_xml "<b>Howdy</b>"
89 89
+    test "#to_tag should dasherize the space when passed a string with spaces as a key" do
+      @xml.to_tag("New   York", 33, @options)
+      assert_xml "<New---York type=\"integer\">33</New---York>"
+    end
+    test "#to_tag should dasherize the space when passed a symbol with spaces as a key" do
+      @xml.to_tag(:"New   York", 33, @options)
+      assert_xml "<New---York type=\"integer\">33</New---York>"
+    end
90 100
     # TODO: test the remaining functions hidden in #to_tag.
91 101
92 102

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.