Skip to content

Commit

Permalink
Source#read_until: Add missing position move on all read
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 2, 2024
1 parent 4444a04 commit 3e3893d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,10 @@ def parse_attributes(prefixes, curr_ns)
raise REXML::ParseException.new(message, @source)
end
quote = match[1]
start_position = @source.position
value = @source.read_until(quote)
unless value.chomp!(quote)
@source.position = start_position
message = "Missing attribute value end quote: <#{name}>: <#{quote}>"
raise REXML::ParseException.new(message, @source)
end
Expand Down
11 changes: 9 additions & 2 deletions lib/rexml/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ def read(term = nil)
end

def read_until(term)
@scanner.scan_until(/#{Regexp.escape(term)}/) or @scanner.rest
data = @scanner.scan_until(/#{Regexp.escape(term)}/)
unless data
data = @scanner.rest
@scanner.pos = @scanner.string.bytesize
end
data
end

def ensure_buffer
Expand Down Expand Up @@ -181,7 +186,9 @@ def read_until(term)
@scanner << readline(term)
end
rescue EOFError
@scanner.rest
rest = @scanner.rest
@scanner.pos = @scanner.string.bytesize
rest
else
read if @scanner.eos? and !@source.eof?
str
Expand Down

0 comments on commit 3e3893d

Please sign in to comment.