-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add more invalid test cases for parsing entitly declaration #183
Changes from 10 commits
8881bd5
77b23ae
b01f4c4
7047bd8
98e0d8f
daaf615
aa634ff
9ecad7c
7c1c59d
4782084
f7d4a08
c211ab5
635af12
96c1d9c
7e95837
8b42c31
8b245cb
556487b
4bada10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,291 @@ def parse(internal_subset) | |
end | ||
|
||
public | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-GEDecl | ||
class TestGeneralEntityDeclaration < self | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-Name | ||
class TestName < self | ||
def test_prohibited_character | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY invalid&name "valid-entity-value">]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 61 | ||
Last 80 unconsumed characters: | ||
invalid&name \"valid-entity-value\">]> | ||
DETAIL | ||
end | ||
end | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EntityDef | ||
class TestEntityDefinition < self | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EntityValue | ||
class TestEntityValue < self | ||
def test_no_quote | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name invalid-entity-value>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 59 | ||
Last 80 unconsumed characters: | ||
valid-name invalid-entity-value>]> | ||
DETAIL | ||
end | ||
|
||
def test_prohibited_character | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name "% &">]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 44 | ||
Last 80 unconsumed characters: | ||
valid-name \"% &\">]> | ||
DETAIL | ||
end | ||
|
||
def test_unnecessary_ndata_declaration | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name "valid-entity-value" NDATA valid-ndata-value>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 83 | ||
Last 80 unconsumed characters: | ||
valid-name \"valid-entity-value\" NDATA valid-ndata-value>]> | ||
DETAIL | ||
end | ||
end | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-ExternalID | ||
class TestExternalID < self | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-SystemLiteral | ||
class TestSystemLiteral < self | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about adding the cases that there is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I added the test cases at 8b42c31 |
||
def test_no_quote_in_system | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name SYSTEM invalid-system-literal>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 68 | ||
Last 80 unconsumed characters: | ||
valid-name SYSTEM invalid-system-literal>]> | ||
DETAIL | ||
end | ||
|
||
def test_no_quote_in_public | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name PUBLIC "valid-pubid-literal" invalid-system-literal>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 90 | ||
Last 80 unconsumed characters: | ||
valid-name PUBLIC \"valid-pubid-literal\" invalid-system-literal>]> | ||
DETAIL | ||
end | ||
end | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PubidLiteral | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PubidChar | ||
class TestPublicIDLiteral < self | ||
def test_no_quote | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is "no quote" a suitable reason? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry. It is my mistake. |
||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name PUBLIC invalid-pubid-literal "valid-system-literal">]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 90 | ||
Last 80 unconsumed characters: | ||
valid-name PUBLIC invalid-pubid-literal \"valid-system-literal\">]> | ||
DETAIL | ||
end | ||
|
||
def test_invalid_pubid_char | ||
Watson1978 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exception = assert_raise(REXML::ParseException) do | ||
# U+3042 HIRAGANA LETTER A | ||
REXML::Document.new("<!DOCTYPE root [<!ENTITY valid-name PUBLIC \"\u3042\" \"valid-system-literal\">]>") | ||
end | ||
assert_equal(<<-DETAIL.force_encoding('utf-8').chomp, exception.to_s.force_encoding('utf-8')) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 74 | ||
Last 80 unconsumed characters: | ||
valid-name PUBLIC \"\u3042\" \"valid-system-literal\">]> | ||
DETAIL | ||
end | ||
end | ||
end | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-NDataDecl | ||
class TestNotationDataDeclaration < self | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-NameChar | ||
def test_prohibited_character | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name PUBLIC "valid-pubid-literal" "valid-system-literal" NDATA invalid&name>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 109 | ||
Last 80 unconsumed characters: | ||
valid-name PUBLIC \"valid-pubid-literal\" \"valid-system-literal\" NDATA invalid&nam | ||
DETAIL | ||
end | ||
end | ||
end | ||
end | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PEDecl | ||
class TestParsedEntityDeclaration < self | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-Name | ||
class TestName < self | ||
def test_prohibited_character | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY % invalid&name "valid-entity-value">]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 63 | ||
Last 80 unconsumed characters: | ||
% invalid&name \"valid-entity-value\">]> | ||
DETAIL | ||
end | ||
end | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PEDef | ||
class TestParsedEntityDefinition < self | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EntityValue | ||
class TestEntityValue < self | ||
def test_no_quote | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name invalid-entity-value>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 61 | ||
Last 80 unconsumed characters: | ||
% valid-name invalid-entity-value>]> | ||
DETAIL | ||
end | ||
|
||
def test_prohibited_character | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name "% &">]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 46 | ||
Last 80 unconsumed characters: | ||
% valid-name \"% &\">]> | ||
DETAIL | ||
end | ||
|
||
def test_unnecessary_ndata_declaration | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name "valid-entity-value" NDATA valid-ndata-value>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 85 | ||
Last 80 unconsumed characters: | ||
% valid-name \"valid-entity-value\" NDATA valid-ndata-value>]> | ||
DETAIL | ||
end | ||
end | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-ExternalID | ||
class TestExternalID < self | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-SystemLiteral | ||
class TestSystemLiteral < self | ||
def test_no_quote_in_system | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name SYSTEM invalid-system-literal>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 70 | ||
Last 80 unconsumed characters: | ||
% valid-name SYSTEM invalid-system-literal>]> | ||
DETAIL | ||
end | ||
|
||
def test_no_quote_in_public | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name PUBLIC "valid-pubid-literal" invalid-system-literal>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 92 | ||
Last 80 unconsumed characters: | ||
% valid-name PUBLIC \"valid-pubid-literal\" invalid-system-literal>]> | ||
DETAIL | ||
end | ||
end | ||
|
||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PubidLiteral | ||
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PubidChar | ||
class TestPublicIDLiteral < self | ||
def test_no_quote | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name PUBLIC invalid-pubid-literal "valid-system-literal">]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 92 | ||
Last 80 unconsumed characters: | ||
% valid-name PUBLIC invalid-pubid-literal \"valid-system-literal\">]> | ||
DETAIL | ||
end | ||
|
||
def test_invalid_pubid_char | ||
Watson1978 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exception = assert_raise(REXML::ParseException) do | ||
# U+3042 HIRAGANA LETTER A | ||
REXML::Document.new("<!DOCTYPE root [<!ENTITY % valid-name PUBLIC \"\u3042\" \"valid-system-literal\">]>") | ||
end | ||
assert_equal(<<-DETAIL.force_encoding('utf-8').chomp, exception.to_s.force_encoding('utf-8')) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 76 | ||
Last 80 unconsumed characters: | ||
% valid-name PUBLIC \"\u3042\" \"valid-system-literal\">]> | ||
DETAIL | ||
end | ||
end | ||
end | ||
|
||
def test_unnecessary_ndata_declaration | ||
exception = assert_raise(REXML::ParseException) do | ||
REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name "valid-entity-value" NDATA valid-ndata-value>]>') | ||
end | ||
assert_equal(<<-DETAIL.chomp, exception.to_s) | ||
Malformed entity declaration | ||
Line: 1 | ||
Position: 85 | ||
Last 80 unconsumed characters: | ||
% valid-name \"valid-entity-value\" NDATA valid-ndata-value>]> | ||
DETAIL | ||
end | ||
end | ||
end | ||
|
||
def test_empty | ||
exception = assert_raise(REXML::ParseException) do | ||
parse(<<-INTERNAL_SUBSET) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this to
TestEntityDefinition
and usetest_entity_value_and_notation_data_declaration
?This test case is for
EntityValue
notEntityDef
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed at c211ab5