diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb index 7126a12d..0fbb94ee 100644 --- a/lib/rexml/parsers/baseparser.rb +++ b/lib/rexml/parsers/baseparser.rb @@ -115,6 +115,7 @@ class BaseParser def initialize( source ) self.stream = source @listeners = [] + @attributes_scanner = StringScanner.new('') end def add_listener( listener ) @@ -601,36 +602,36 @@ def parse_attributes(prefixes, curr_ns) return attributes, closed if raw_attributes.nil? return attributes, closed if raw_attributes.empty? - scanner = StringScanner.new(raw_attributes) - until scanner.eos? - if scanner.scan(/\s+/) - break if scanner.eos? + @attributes_scanner.string = raw_attributes + until @attributes_scanner.eos? + if @attributes_scanner.scan(/\s+/) + break if @attributes_scanner.eos? end - pos = scanner.pos + pos = @attributes_scanner.pos loop do - break if scanner.scan(ATTRIBUTE_PATTERN) - unless scanner.scan(QNAME) - message = "Invalid attribute name: <#{scanner.rest}>" + break if @attributes_scanner.scan(ATTRIBUTE_PATTERN) + unless @attributes_scanner.scan(QNAME) + message = "Invalid attribute name: <#{@attributes_scanner.rest}>" raise REXML::ParseException.new(message, @source) end - name = scanner[0] - unless scanner.scan(/\s*=\s*/um) + name = @attributes_scanner[0] + unless @attributes_scanner.scan(/\s*=\s*/um) message = "Missing attribute equal: <#{name}>" raise REXML::ParseException.new(message, @source) end - quote = scanner.scan(/['"]/) + quote = @attributes_scanner.scan(/['"]/) unless quote message = "Missing attribute value start quote: <#{name}>" raise REXML::ParseException.new(message, @source) end - unless scanner.scan(/.*#{Regexp.escape(quote)}/um) + unless @attributes_scanner.scan(/.*#{Regexp.escape(quote)}/um) match_data = @source.match(/^(.*?)(\/)?>/um, true) if match_data - scanner << "/" if closed - scanner << ">" - scanner << match_data[1] - scanner.pos = pos + @attributes_scanner << "/" if closed + @attributes_scanner << ">" + @attributes_scanner << match_data[1] + @attributes_scanner.pos = pos closed = !match_data[2].nil? next end @@ -639,11 +640,11 @@ def parse_attributes(prefixes, curr_ns) raise REXML::ParseException.new(message, @source) end end - name = scanner[1] - prefix = scanner[2] - local_part = scanner[3] - # quote = scanner[4] - value = scanner[5] + name = @attributes_scanner[1] + prefix = @attributes_scanner[2] + local_part = @attributes_scanner[3] + # quote = @attributes_scanner[4] + value = @attributes_scanner[5] if prefix == "xmlns" if local_part == "xml" if value != "http://www.w3.org/XML/1998/namespace"