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

Reduced regular expression processing in the form of processing white space first #237

Merged
merged 1 commit into from
Jan 26, 2025
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
13 changes: 8 additions & 5 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,11 @@ def pull_event
raise REXML::ParseException.new(message, @source)
end
name = parse_name(base_error_message)
if @source.match?(/\s*\[/um, true)
@source.match?(/\s*/um, true) # skip spaces
if @source.match?("[", true)
id = [nil, nil, nil]
@document_status = :in_doctype
elsif @source.match?(/\s*>/um, true)
elsif @source.match?(">", true)
id = [nil, nil, nil]
@document_status = :after_doctype
@source.ensure_buffer
Expand All @@ -312,9 +313,10 @@ def pull_event
# For backward compatibility
id[1], id[2] = id[2], nil
end
if @source.match?(/\s*\[/um, true)
@source.match?(/\s*/um, true) # skip spaces
if @source.match?("[", true)
@document_status = :in_doctype
elsif @source.match?(/\s*>/um, true)
elsif @source.match?(">", true)
@document_status = :after_doctype
@source.ensure_buffer
else
Expand Down Expand Up @@ -409,7 +411,8 @@ def pull_event
id = parse_id(base_error_message,
accept_external_id: true,
accept_public_id: true)
unless @source.match?(/\s*>/um, true)
@source.match?(/\s*/um, true) # skip spaces
unless @source.match?(">", true)
message = "#{base_error_message}: garbage before end >"
raise REXML::ParseException.new(message, @source)
end
Expand Down
10 changes: 5 additions & 5 deletions test/parse/test_document_type_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_no_literal
Line: 3
Position: 26
Last 80 unconsumed characters:
SYSTEM> <r/>
SYSTEM> <r/>
DETAIL
end

Expand Down Expand Up @@ -200,7 +200,7 @@ def test_content_double_quote
Line: 3
Position: 62
Last 80 unconsumed characters:
PUBLIC 'double quote " is invalid' "r.dtd"> <r/>
PUBLIC 'double quote " is invalid' "r.dtd"> <r/>
DETAIL
end

Expand Down Expand Up @@ -228,10 +228,10 @@ def test_garbage_after_literal
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed DOCTYPE: garbage after external ID
Line: 3
Position: 65
Line: 1
Position: 58
Last 80 unconsumed characters:
x'> <r/>
x'>
DETAIL
end

Expand Down
Loading