Skip to content

Commit

Permalink
Add test for Name
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 23, 2024
1 parent aa634ff commit 9ecad7c
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions test/parse/test_entity_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ def parse(internal_subset)

# 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
Expand Down Expand Up @@ -121,16 +137,17 @@ def test_invalid_pubid_char

# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-NDataDecl
class TestNotationDataDeclaration < self
def test_no_quote
# 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" invalid-ndata valid-ndata-value>]>')
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: 122
Position: 109
Last 80 unconsumed characters:
valid-name PUBLIC \"valid-pubid-literal\" \"valid-system-literal\" invalid-ndata val
valid-name PUBLIC \"valid-pubid-literal\" \"valid-system-literal\" NDATA invalid&nam
DETAIL
end
end
Expand All @@ -142,6 +159,22 @@ def test_no_quote
class TestParsedEntityDeclaration < self
# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PEDef
class TestParsedEntityDefinition < 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-EntityValue
class TestEntityValue < self
def test_no_quote
Expand Down

0 comments on commit 9ecad7c

Please sign in to comment.