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

Separate IOSource#ensure_buffer from IOSource#match. #118

Merged
merged 1 commit into from
Mar 6, 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
5 changes: 5 additions & 0 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def pull_event
return @stack.shift if @stack.size > 0
#STDERR.puts @source.encoding
#STDERR.puts "BUFFER = #{@source.buffer.inspect}"

@source.ensure_buffer
if @document_status == nil
start_position = @source.position
if @source.match("<?", true)
Expand All @@ -236,6 +238,7 @@ def pull_event
elsif @source.match(/\s*>/um, true)
id = [nil, nil, nil]
@document_status = :after_doctype
@source.ensure_buffer
else
id = parse_id(base_error_message,
accept_external_id: true,
Expand All @@ -248,6 +251,7 @@ def pull_event
@document_status = :in_doctype
elsif @source.match(/\s*>/um, true)
@document_status = :after_doctype
@source.ensure_buffer
else
message = "#{base_error_message}: garbage after external ID"
raise REXML::ParseException.new(message, @source)
Expand Down Expand Up @@ -646,6 +650,7 @@ def parse_attributes(prefixes, curr_ns)
raise REXML::ParseException.new(message, @source)
end
unless scanner.scan(/.*#{Regexp.escape(quote)}/um)
@source.ensure_buffer
match_data = @source.match(/^(.*?)(\/)?>/um, true)
if match_data
scanner << "/" if closed
Expand Down
8 changes: 7 additions & 1 deletion lib/rexml/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def encoding=(enc)
def read
end

def ensure_buffer
end

def match(pattern, cons=false)
if cons
@scanner.scan(pattern).nil? ? nil : @scanner
Expand Down Expand Up @@ -165,11 +168,14 @@ def read
end
end

def ensure_buffer
read if @scanner.eos? && @source
end

# Note: When specifying a string for 'pattern', it must not include '>' except in the following formats:
# - ">"
# - "XXX>" (X is any string excluding '>')
def match( pattern, cons=false )
read if @scanner.eos? && @source
while true
if cons
md = @scanner.scan(pattern)
Expand Down