Skip to content
Merged
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: 4 additions & 3 deletions lib/rexml/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,10 @@ def Text::normalize( input, doctype=nil, entity_filter=nil )
if doctype
# Replace all ampersands that aren't part of an entity
doctype.entities.each_value do |entity|
copy = copy.gsub( entity.value,
"&#{entity.name};" ) if entity.value and
not( entity_filter and entity_filter.include?(entity.name) )
# Skip an empty value because String#gsub("") matches at every position
next if entity.value.nil? or entity.value.empty?
next if entity_filter and entity_filter.include?(entity.name)
copy = copy.gsub( entity.value, "&#{entity.name};" )
end
else
# Replace all ampersands that aren't part of an entity
Expand Down
12 changes: 12 additions & 0 deletions test/test_attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ def test_namespace_declaration
assert_equal(true, REXML::Attribute.new("xmlns:name").namespace_declaration?)
# REXML::Attribute.new("xmlns:xmlns") is not tested because it's invalid
end

def test_to_string_entity
document = REXML::Document.new(<<-XML)
<!DOCTYPE root [
<!ENTITY empty "">
<!ENTITY a "aaa">
]>
<root/>
XML
document.root.add_attribute("attr", "abc aaa")
assert_equal("<root attr='abc &a;'/>", document.root.to_s)
end
end
end
12 changes: 12 additions & 0 deletions test/test_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def test_new_text_entity_filter_custom
Text.new(text, false, document.root, nil, ["b"]).to_s)
end

def test_new_text_empty_entity
document = REXML::Document.new(<<-XML)
<!DOCTYPE root [
<!ENTITY empty "">
<!ENTITY a "aaa">
]>
<root/>
XML
assert_equal("abc &a;",
Text.new("abc aaa", false, document.root).to_s)
end

def test_shift_operator_chain
text = Text.new("original\r\n")
text << "append1\r\n" << "append2\r\n"
Expand Down
Loading