Skip to content

Improve CDATA and comment parse performance #246

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

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
6 changes: 2 additions & 4 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@ def pull_event
end
return [ :end_element, last_tag ]
elsif @source.match?("!", true)
md = @source.match(/([^>]*>)/um)
#STDERR.puts "SOURCE BUFFER = #{source.buffer}, #{source.buffer.size}"
raise REXML::ParseException.new("Malformed node", @source) unless md
if @source.match?("--", true)
return [ :comment, process_comment ]
elsif @source.match?("[CDATA[", true)
Expand All @@ -461,9 +459,9 @@ def pull_event
else
raise REXML::ParseException.new("Malformed CDATA: Missing end ']]>'", @source)
end
else
raise REXML::ParseException.new("Malformed node: Started with '<!' but not a comment nor CDATA", @source)
end
raise REXML::ParseException.new( "Declarations can only occur "+
"in the doctype declaration.", @source)
elsif @source.match?("?", true)
return process_instruction
else
Expand Down
13 changes: 13 additions & 0 deletions test/parse/test_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ def test_doctype_malformed_comment_end
DETAIL
end

def test_after_doctype_malformed_node
exception = assert_raise(REXML::ParseException) do
parse("<a><!a")
end
assert_equal(<<~DETAIL.chomp, exception.to_s)
Malformed node: Started with '<!' but not a comment nor CDATA
Line: 1
Position: 6
Last 80 unconsumed characters:
a
DETAIL
end

def test_after_doctype_unclosed_comment
exception = assert_raise(REXML::ParseException) do
parse("<a><!-->")
Expand Down