@@ -211,8 +211,9 @@ def pull_event
211
211
#STDERR.puts @source.encoding
212
212
#STDERR.puts "BUFFER = #{@source.buffer.inspect}"
213
213
if @document_status == nil
214
+ start_position = @source . position
214
215
if @source . match ( "<?" , true )
215
- return process_instruction
216
+ return process_instruction ( start_position )
216
217
elsif @source . match ( "<!" , true )
217
218
if @source . match ( "--" , true )
218
219
return [ :comment , @source . match ( /(.*?)-->/um , true ) [ 1 ] ]
@@ -224,7 +225,7 @@ def pull_event
224
225
else
225
226
message = "#{ base_error_message } : invalid name"
226
227
end
227
- @source . string = "<!DOCTYPE" + @source . buffer
228
+ @source . position = start_position
228
229
raise REXML ::ParseException . new ( message , @source )
229
230
end
230
231
@nsstack . unshift ( curr_ns = Set . new )
@@ -266,6 +267,7 @@ def pull_event
266
267
end
267
268
if @document_status == :in_doctype
268
269
@source . match ( /\s */um , true ) # skip spaces
270
+ start_position = @source . position
269
271
if @source . match ( "<!" , true )
270
272
if @source . match ( "ELEMENT" , true )
271
273
md = @source . match ( /(.*?)>/um , true )
@@ -325,7 +327,7 @@ def pull_event
325
327
else
326
328
message = "#{ base_error_message } : invalid name"
327
329
end
328
- @source . string = " <!NOTATION" + @source . buffer
330
+ @source . position = start_position
329
331
raise REXML ::ParseException . new ( message , @source )
330
332
end
331
333
name = parse_name ( base_error_message )
@@ -355,6 +357,7 @@ def pull_event
355
357
@source . match ( /\s */um , true )
356
358
end
357
359
begin
360
+ start_position = @source . position
358
361
if @source . match ( "<" , true )
359
362
if @source . match ( "/" , true )
360
363
@nsstack . shift
@@ -367,7 +370,7 @@ def pull_event
367
370
if md . nil? or last_tag != md [ 1 ]
368
371
message = "Missing end tag for '#{ last_tag } '"
369
372
message += " (got '#{ md [ 1 ] } ')" if md
370
- @source . string = "</" + @source . buffer if md . nil?
373
+ @source . position = start_position if md . nil?
371
374
raise REXML ::ParseException . new ( message , @source )
372
375
end
373
376
return [ :end_element , last_tag ]
@@ -391,12 +394,12 @@ def pull_event
391
394
raise REXML ::ParseException . new ( "Declarations can only occur " +
392
395
"in the doctype declaration." , @source )
393
396
elsif @source . match ( "?" , true )
394
- return process_instruction
397
+ return process_instruction ( start_position )
395
398
else
396
399
# Get the next tag
397
400
md = @source . match ( TAG_PATTERN , true )
398
401
unless md
399
- @source . string = "<" + @source . buffer
402
+ @source . position = start_position
400
403
raise REXML ::ParseException . new ( "malformed XML: missing tag start" , @source )
401
404
end
402
405
tag = md [ 1 ]
@@ -578,11 +581,11 @@ def parse_id_invalid_details(accept_external_id:,
578
581
end
579
582
end
580
583
581
- def process_instruction
584
+ def process_instruction ( start_position )
582
585
match_data = @source . match ( INSTRUCTION_END , true )
583
586
unless match_data
584
587
message = "Invalid processing instruction node"
585
- @source . string = "<?" + @source . buffer
588
+ @source . position = start_position
586
589
raise REXML ::ParseException . new ( message , @source )
587
590
end
588
591
if @document_status . nil? and match_data [ 1 ] == "xml"
@@ -625,7 +628,7 @@ def parse_attributes(prefixes, curr_ns)
625
628
break if scanner . eos?
626
629
end
627
630
628
- pos = scanner . pos
631
+ start_position = scanner . pos
629
632
while true
630
633
break if scanner . scan ( ATTRIBUTE_PATTERN )
631
634
unless scanner . scan ( QNAME )
@@ -648,7 +651,7 @@ def parse_attributes(prefixes, curr_ns)
648
651
scanner << "/" if closed
649
652
scanner << ">"
650
653
scanner << match_data [ 1 ]
651
- scanner . pos = pos
654
+ scanner . pos = start_position
652
655
closed = !match_data [ 2 ] . nil?
653
656
next
654
657
end
0 commit comments