-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a "malformed comment" check for top-level comments (#145)
This check was missing. Therefore, `REXML::Document.new("<!--")` raised the ``undefined method `[]' for nil`` error, for example. This PR also adds tests for "malformed comment" checks. --------- Co-authored-by: Sutou Kouhei <[email protected]>
- Loading branch information
1 parent
6415113
commit b5bf109
Showing
2 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
require "test/unit" | ||
require "rexml/document" | ||
|
||
module REXMLTests | ||
class TestParseComment < Test::Unit::TestCase | ||
def parse(xml) | ||
REXML::Document.new(xml) | ||
end | ||
|
||
class TestInvalid < self | ||
def test_toplevel_unclosed_comment | ||
exception = assert_raise(REXML::ParseException) do | ||
parse("<!--") | ||
end | ||
assert_equal(<<~DETAIL, exception.to_s) | ||
Unclosed comment | ||
Line: 1 | ||
Position: 4 | ||
Last 80 unconsumed characters: | ||
DETAIL | ||
end | ||
|
||
def test_toplevel_malformed_comment_inner | ||
exception = assert_raise(REXML::ParseException) do | ||
parse("<!-- -- -->") | ||
end | ||
assert_equal(<<~DETAIL, exception.to_s) | ||
Malformed comment | ||
Line: 1 | ||
Position: 11 | ||
Last 80 unconsumed characters: | ||
DETAIL | ||
end | ||
|
||
def test_toplevel_malformed_comment_end | ||
exception = assert_raise(REXML::ParseException) do | ||
parse("<!-- --->") | ||
end | ||
assert_equal(<<~DETAIL, exception.to_s) | ||
Malformed comment | ||
Line: 1 | ||
Position: 9 | ||
Last 80 unconsumed characters: | ||
DETAIL | ||
end | ||
|
||
def test_doctype_malformed_comment_inner | ||
exception = assert_raise(REXML::ParseException) do | ||
parse("<!DOCTYPE foo [<!-- -- -->") | ||
end | ||
assert_equal(<<~DETAIL, exception.to_s) | ||
Malformed comment | ||
Line: 1 | ||
Position: 26 | ||
Last 80 unconsumed characters: | ||
DETAIL | ||
end | ||
|
||
def test_doctype_malformed_comment_end | ||
exception = assert_raise(REXML::ParseException) do | ||
parse("<!DOCTYPE foo [<!-- --->") | ||
end | ||
assert_equal(<<~DETAIL, exception.to_s) | ||
Malformed comment | ||
Line: 1 | ||
Position: 24 | ||
Last 80 unconsumed characters: | ||
DETAIL | ||
end | ||
|
||
def test_after_doctype_malformed_comment_inner | ||
exception = assert_raise(REXML::ParseException) do | ||
parse("<a><!-- -- -->") | ||
end | ||
assert_equal(<<~DETAIL, exception.to_s) | ||
Malformed comment | ||
Line: 1 | ||
Position: 14 | ||
Last 80 unconsumed characters: | ||
DETAIL | ||
end | ||
|
||
def test_after_doctype_malformed_comment_end | ||
exception = assert_raise(REXML::ParseException) do | ||
parse("<a><!-- --->") | ||
end | ||
assert_equal(<<~DETAIL, exception.to_s) | ||
Malformed comment | ||
Line: 1 | ||
Position: 12 | ||
Last 80 unconsumed characters: | ||
DETAIL | ||
end | ||
end | ||
end | ||
end |