Skip to content

Commit

Permalink
Raise ParseException with proper message
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 19, 2024
1 parent 36ba79e commit 93ec28f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ def pull_event
raise REXML::ParseException.new( "Bad ELEMENT declaration!", @source ) if md.nil?
return [ :elementdecl, "<!ELEMENT" + md[1] ]
elsif @source.match("ENTITY", true)
match = [:entitydecl, *@source.match(Private::ENTITYDECL_PATTERN, true, term: Private::ENTITY_TERM).captures.compact]
scanner = @source.match(Private::ENTITYDECL_PATTERN, true, term: Private::ENTITY_TERM)
unless scanner
raise REXML::ParseException.new("Malformed entity declaration", @source)
end
match = [:entitydecl, *scanner.captures.compact]
ref = false
if match[1] == '%'
ref = true
Expand Down
9 changes: 8 additions & 1 deletion test/parse/test_entity_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ def parse(internal_subset)

public
def test_empty
assert_raise(REXML::ParseException) do
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!ENTITY>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed entity declaration
Line: 5
Position: 70
Last 80 unconsumed characters:
> ]> <r/>
DETAIL
end

def test_linear_performance_gt
Expand Down

0 comments on commit 93ec28f

Please sign in to comment.