File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,11 @@ module Private
157
157
DEFAULT_ENTITIES_PATTERNS[term] = /&#{term};/
158
158
end
159
159
XML_PREFIXED_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
160
+
161
+ QUOTE = [].tap { |x|
162
+ x['"'.ord] = '"'
163
+ x["'".ord] = "'"
164
+ }
160
165
end
161
166
private_constant :Private
162
167
@@ -766,6 +771,19 @@ def process_instruction
766
771
[:processing_instruction, name, content]
767
772
end
768
773
774
+ if StringScanner::Version < "3.1.1"
775
+ def get_quote
776
+ @source.match(/(['"])/, true)&.[](1)
777
+ end
778
+ else
779
+ def get_quote
780
+ if quote = Private::QUOTE[@source.peek_byte]
781
+ @source.scan_byte
782
+ end
783
+ quote
784
+ end
785
+ end
786
+
769
787
def parse_attributes(prefixes)
770
788
attributes = {}
771
789
expanded_names = {}
@@ -785,11 +803,10 @@ def parse_attributes(prefixes)
785
803
message = "Missing attribute equal: <#{name}>"
786
804
raise REXML::ParseException.new(message, @source)
787
805
end
788
- unless match = @source.match(/(['"])/, true)
806
+ unless quote = get_quote
789
807
message = "Missing attribute value start quote: <#{name}>"
790
808
raise REXML::ParseException.new(message, @source)
791
809
end
792
- quote = match[1]
793
810
start_position = @source.position
794
811
value = @source.read_until(quote)
795
812
unless value.chomp!(quote)
Original file line number Diff line number Diff line change @@ -158,6 +158,14 @@ def position=(pos)
158
158
@scanner.pos = pos
159
159
end
160
160
161
+ def peek_byte
162
+ @scanner.peek_byte
163
+ end
164
+
165
+ def scan_byte
166
+ @scanner.scan_byte
167
+ end
168
+
161
169
# @return true if the Source is exhausted
162
170
def empty?
163
171
@scanner.eos?
You can’t perform that action at this time.
0 commit comments