Skip to content

Commit

Permalink
Add mixed quote tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 23, 2024
1 parent c211ab5 commit 635af12
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions test/parse/test_entity_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def test_prohibited_character
valid-name \"% &\">]>
DETAIL
end

def test_mixed_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
end

# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-ExternalID
Expand Down Expand Up @@ -102,6 +115,32 @@ def test_no_quote_in_public
valid-name PUBLIC \"valid-pubid-literal\" invalid-system-literal>]>
DETAIL
end

def test_mixed_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_mixed_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
Expand Down Expand Up @@ -133,6 +172,19 @@ def test_invalid_pubid_char
valid-name PUBLIC \"\u3042\" \"valid-system-literal\">]>
DETAIL
end

def test_mixed_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
end
end

Expand Down Expand Up @@ -215,6 +267,19 @@ def test_prohibited_character
% valid-name \"% &\">]>
DETAIL
end

def test_mixed_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: 63
Last 80 unconsumed characters:
% valid-name 'invalid-entity-value\">]>
DETAIL
end
end

# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-ExternalID
Expand Down Expand Up @@ -246,6 +311,32 @@ def test_no_quote_in_public
% valid-name PUBLIC \"valid-pubid-literal\" invalid-system-literal>]>
DETAIL
end

def test_mixed_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: 72
Last 80 unconsumed characters:
% valid-name SYSTEM \"invalid-system-literal'>]>
DETAIL
end

def test_mixed_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: 94
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
Expand Down Expand Up @@ -277,6 +368,19 @@ def test_invalid_pubid_char
% valid-name PUBLIC \"\u3042\" \"valid-system-literal\">]>
DETAIL
end

def test_mixed_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: 94
Last 80 unconsumed characters:
% valid-name PUBLIC 'invalid-pubid-literal\" \"valid-system-literal\">]>
DETAIL
end
end
end

Expand Down

0 comments on commit 635af12

Please sign in to comment.