Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not output :text event after the root tag is closed #167

Merged
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
1 change: 1 addition & 0 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def pull_event
unless /\A\s*\z/.match?(text)
raise ParseException.new("Malformed XML: Extra content at the end of the document (got '#{text}')", @source)
end
return pull_event
end
return [ :text, text ]
end
Expand Down
15 changes: 15 additions & 0 deletions test/parse/test_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,20 @@ def test_after_root
DETAIL
end
end

def test_whitespace_characters_after_root
parser = REXML::Parsers::BaseParser.new('<a>b</a> ')

events = []
while parser.has_next?
event = parser.pull
case event[0]
when :text
events << event[1]
end
end

assert_equal(["b"], events)
end
end
end
1 change: 0 additions & 1 deletion test/parser/test_ultra_light.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def test_entity_declaration
[:entitydecl, "name", "value"]
],
[:start_element, :parent, "root", {}],
[:text, "\n"],
],
parse(<<-INTERNAL_SUBSET))
<!ENTITY name "value">
Expand Down
2 changes: 1 addition & 1 deletion test/test_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def test_deep_clone
end

def test_whitespace_before_root
a = <<EOL
a = <<EOL.chomp
<?xml version='1.0'?>
<blo>
<wak>
Expand Down
2 changes: 1 addition & 1 deletion test/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def test_utf_16

actual_xml = ""
document.write(actual_xml)
expected_xml = <<-EOX.encode("UTF-16BE")
expected_xml = <<-EOX.chomp.encode("UTF-16BE")
\ufeff<?xml version='1.0' encoding='UTF-16'?>
<message>Hello world!</message>
EOX
Expand Down