Commits

Dave Dribin  committed 4762784

Catch XML parse exceptions, and ignore them

  • Participants
  • Parent commits c95d787

Comments (0)

Files changed (2)

File ruby/lib/lolspeak.rb

     #
     def translate_xml_element!(xml_element, &filter)
       xml_element.texts.each do |text|
-        string = REXML::Text::unnormalize(text.to_s)
+        string = text.to_s
+        string = REXML::Text::unnormalize(string)
         string = self.translate_words(string) do |w|
           w = REXML::Text::normalize(w)
           w = filter.call(w) if !filter.nil?
           w
         end
-        new_text = REXML::Text.new(string, true, nil, true)
-        text.replace_with(new_text)
+        begin
+          new_text = REXML::Text.new(string, true, nil, true)
+          text.replace_with(new_text)
+        rescue
+        end
       end
     end
 

File ruby/test/tranzlator_test.rb

       t.translate_xml_string("<b>&nbsp;hi</b>")
   end
   
+  def test_tranzlate_xml_string_with_invalid_ampersand
+    t = new_tranzlator
+    assert_equal "<b>dungeons &amp; dragons</b>",
+      t.translate_xml_string("<b>dungeons &amp; dragons</b>")
+  end
+  
   def test_tranzlate_xml_string_escape
     t = new_tranzlator
     assert_equal "<b>f&amp;#^bar</b>",