diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index 60ae34e7..3ad3fe13 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -263,12 +263,7 @@ def Functions::string_length( string ) end def Functions::normalize_space( string=nil ) - string = string(@@context[:node]) if string.nil? - if string.kind_of? Array - string.collect{|x| x.to_s.strip.gsub(/\s+/um, ' ') if x} - else - string.to_s.strip.gsub(/\s+/um, ' ') - end + string(string).strip.gsub(/\s+/um, ' ') end # This is entirely Mike Stok's beast diff --git a/test/functions/test_base.rb b/test/functions/test_base.rb index daa38156..9e6cab8c 100644 --- a/test/functions/test_base.rb +++ b/test/functions/test_base.rb @@ -242,13 +242,12 @@ def test_normalize_space_strings Dessert \t\t after dinner XML - normalized_texts = REXML::XPath.each(REXML::Document.new(source), "normalize-space(//text())").to_a - assert_equal([ - "breakfast boosts concentration", - "Coffee beans aroma", - "Dessert after dinner", - ], - normalized_texts) + normalized_text = REXML::XPath.each(REXML::Document.new(source), "normalize-space(//text())").to_a + doc = REXML::Document.new(source) + # First node should be used for normalize-space, and the rest should be ignored. + assert_equal(["breakfast boosts concentration"], REXML::XPath.match(doc, "normalize-space(//text())")) + assert_equal(["Coffee beans aroma"], REXML::XPath.match(doc, "normalize-space(//c/text())")) + assert_equal(["Dessert after dinner"], REXML::XPath.match(doc, "normalize-space(//d/text())")) end def test_string_nil_without_context