Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/rexml/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions test/functions/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,12 @@ def test_normalize_space_strings
</c><d> Dessert
\t\t after dinner</d></a>
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
Expand Down
Loading