Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 22, 2024
1 parent 16d3d37 commit edc80f8
Showing 1 changed file with 45 additions and 44 deletions.
89 changes: 45 additions & 44 deletions test/parse/test_entity_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,152 +25,153 @@ def parse(internal_subset)
public

class TestGeneralEntityDeclration < self
def test_garbaged_after_entity_definition
def test_invalid_entity_definition
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY "foo" xxx > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY "valid-name" invalid-entity-definition > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 39
Position: 68
Last 80 unconsumed characters:
\"foo\" xxx > ]>
\"valid-name\" invalid-entity-definition > ]>
DETAIL
end

class TestSystemExternalEntities < self
def test_garbaged_between_system_and_literal
def test_invalid_external_entity_before_system_literal
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo SYSTEM xxx "bar" > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name SYSTEM invalid-external-entity "valid-system-literal" > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 50
Position: 94
Last 80 unconsumed characters:
foo SYSTEM xxx \"bar\" > ]>
valid-name SYSTEM invalid-external-entity \"valid-system-literal\" > ]>
DETAIL
end

def test_garbaged_after_literal
def test_invalid_external_entity_after_system_literal
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo SYSTEM "bar" xxx > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name SYSTEM "valid-system-literal" invalid-external-entity > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 50
Position: 94
Last 80 unconsumed characters:
foo SYSTEM \"bar\" xxx > ]>
valid-name SYSTEM \"valid-system-literal\" invalid-external-entity > ]>
DETAIL
end

def test_garbaged_between_literal_and_ndata_declaration
def test_invalid_external_entity_before_ndata_declaration
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo SYSTEM "bar" xxx NDATA gif > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name SYSTEM "valid-system-literal" invalid-external-entity NDATA gif > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 60
Position: 104
Last 80 unconsumed characters:
foo SYSTEM \"bar\" xxx NDATA gif > ]>
valid-name SYSTEM \"valid-system-literal\" invalid-external-entity NDATA gif > ]>
DETAIL
end

def test_garbaged_after_ndata_declaration
def test_invalid_external_entity_after_ndata_declaration
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo SYSTEM "bar" NDATA gif xxx > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name SYSTEM "valid-system-literal" NDATA gif invalid-external-entity > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 60
Position: 104
Last 80 unconsumed characters:
foo SYSTEM \"bar\" NDATA gif xxx > ]>
valid-name SYSTEM \"valid-system-literal\" NDATA gif invalid-external-entity > ]>
DETAIL
end
end

class TestPublicExternalEntities < self
def test_garbaged_between_public_and_first_literal
def test_invalid_external_entity_before_pubid_literal
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo PUBLIC xxx "bar" "baz" > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name PUBLIC invalid-external-entity "valid-pubid-literal" "valid-system-literal" > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 56
Position: 116
Last 80 unconsumed characters:
foo PUBLIC xxx \"bar\" \"baz\" > ]>
valid-name PUBLIC invalid-external-entity \"valid-pubid-literal\" \"valid-system-li
DETAIL
end

def test_garbaged_between_literals
def test_invalid_external_entity_after_pubid_literal
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo PUBLIC "bar" xxx "baz" > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name PUBLIC "valid-pubid-literal" invalid-external-entity "valid-system-literal" > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 56
Position: 116
Last 80 unconsumed characters:
foo PUBLIC \"bar\" xxx \"baz\" > ]>
valid-name PUBLIC \"valid-pubid-literal\" invalid-external-entity \"valid-system-li
DETAIL
end

def test_garbaged_after_literals
def test_invalid_external_entity_after_system_literal
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo PUBLIC "bar" "baz" xxx > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name PUBLIC "valid-pubid-literal" "valid-system-literal" invalid-external-entity > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 56
Position: 116
Last 80 unconsumed characters:
foo PUBLIC \"bar\" \"baz\" xxx > ]>
valid-name PUBLIC \"valid-pubid-literal\" \"valid-system-literal\" invalid-external-
DETAIL
end

def test_garbaged_between_literal_and_ndata_declaration
def test_invalid_external_entity_before_ndata_declaration
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo PUBLIC "bar" "baz" xxx NDATA gif > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name PUBLIC "valid-pubid-literal" "valid-system-literal" invalid-external-entity NDATA gif > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 66
Position: 126
Last 80 unconsumed characters:
foo PUBLIC \"bar\" \"baz\" xxx NDATA gif > ]>
valid-name PUBLIC \"valid-pubid-literal\" \"valid-system-literal\" invalid-external-
DETAIL
end

def test_garbaged_after_ndata_declaration
def test_invalid_external_entity_after_ndata_declaration
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo PUBLIC "bar" "baz" NDATA gif xxx > ]>')
REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name PUBLIC "valid-pubid-literal" "valid-system-literal" NDATA gif invalid-external-entity > ]>')
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 1
Position: 66
Position: 126
Last 80 unconsumed characters:
foo PUBLIC \"bar\" \"baz\" NDATA gif xxx > ]>
valid-name PUBLIC \"valid-pubid-literal\" \"valid-system-literal\" NDATA gif invalid
DETAIL
end
end
end

class TestPublicIDLiteral < self
def test_pubid_literal
def test_invalid_pubid_char
exception = assert_raise(REXML::ParseException) do
REXML::Document.new('<!DOCTYPE root [<!ENTITY foo PUBLIC "あいう" "bar" > ]>')
# U+3042 HIRAGANA LETTER A
REXML::Document.new("<!DOCTYPE root [<!ENTITY valid-name PUBLIC \"\u3042\" \"valid-system-literal\" > ]>")
end
assert_equal(<<-DETAIL.chomp, exception.to_s.force_encoding('utf-8'))
Malformed entity declaration
Line: 1
Position: 58
Position: 76
Last 80 unconsumed characters:
foo PUBLIC \"あいう\" \"bar\" > ]>
valid-name PUBLIC \"\" \"valid-system-literal\" > ]>
DETAIL
end
end
Expand Down

0 comments on commit edc80f8

Please sign in to comment.