Skip to content
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

Fix method scope in test in order to invoke the tests properly and fix exception message #182

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
match_data = @source.match(Private::ENTITYDECL_PATTERN, true, term: Private::ENTITY_TERM)
unless match_data
raise REXML::ParseException.new("Malformed entity declaration", @source)
end
match = [:entitydecl, *match_data.captures.compact]
ref = false
if match[1] == '%'
ref = true
Expand Down
17 changes: 11 additions & 6 deletions test/parse/test_entity_declaration.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# frozen_string_literal: false
require 'test/unit'
require 'rexml/document'
require "test/unit"
require "core_assertions"

require "rexml/document"

module REXMLTests
class TestParseEntityDeclaration < Test::Unit::TestCase
include Test::Unit::CoreAssertions

private
def xml(internal_subset)
<<-XML
Expand All @@ -18,25 +22,26 @@ def parse(internal_subset)
REXML::Document.new(xml(internal_subset)).doctype
end

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits] There is a unnecessary white space.

Suggested change
> ]> <r/>
> ]> <r/>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the exception message contains trailing space.
So I cannot remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see. I'm so sorry mm

DETAIL
end

def test_linear_performance_gt
seq = [10000, 50000, 100000, 150000, 200000]
assert_linear_performance(seq, rehearsal: 10) do |n|
REXML::Document.new('<!DOCTYPE rubynet [<!ENTITY rbconfig.ruby_version "' + '>' * n + '">')
REXML::Document.new('<!DOCTYPE rubynet [<!ENTITY rbconfig.ruby_version "' + '>' * n + '">]>')
end
end
end
Expand Down