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

Use StringScanner#peek_byte to get double or single quotation mark #227

Merged
merged 1 commit into from
Dec 20, 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
22 changes: 20 additions & 2 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,25 @@ def process_instruction
[:processing_instruction, name, content]
end

if StringScanner::Version < "3.1.1"
def scan_quote
@source.match(/(['"])/, true)&.[](1)
end
else
def scan_quote
case @source.peek_byte
when 34 # '"'.ord
@source.scan_byte
'"'
when 39 # "'".ord
@source.scan_byte
"'"
else
nil
end
end
end

def parse_attributes(prefixes)
attributes = {}
expanded_names = {}
Expand All @@ -785,11 +804,10 @@ def parse_attributes(prefixes)
message = "Missing attribute equal: <#{name}>"
raise REXML::ParseException.new(message, @source)
end
unless match = @source.match(/(['"])/, true)
unless quote = scan_quote
message = "Missing attribute value start quote: <#{name}>"
raise REXML::ParseException.new(message, @source)
end
quote = match[1]
start_position = @source.position
value = @source.read_until(quote)
unless value.chomp!(quote)
Expand Down
8 changes: 8 additions & 0 deletions lib/rexml/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ def position=(pos)
@scanner.pos = pos
end

def peek_byte
@scanner.peek_byte
end

def scan_byte
@scanner.scan_byte
end

# @return true if the Source is exhausted
def empty?
@scanner.eos?
Expand Down
Loading