diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb
index 60ae34e7..a72fca5b 100644
--- a/lib/rexml/functions.rb
+++ b/lib/rexml/functions.rb
@@ -262,13 +262,8 @@ def Functions::string_length( string )
string(string).length
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
+ def Functions::normalize_space( object=@@context[:node] )
+ string(object).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..eb67fa3f 100644
--- a/test/functions/test_base.rb
+++ b/test/functions/test_base.rb
@@ -242,13 +242,18 @@ 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)
+ 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_normalize_space_without_argument
+ source = "- foo
- bar
- baz
"
+ doc = REXML::Document.new(source)
+ match = REXML::XPath.match(doc, "//item[normalize-space()='bar']")
+ assert_equal([" bar "], match.map(&:text))
end
def test_string_nil_without_context