File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -644,7 +644,10 @@ def process_instruction(start_position)
644
644
@source . position = start_position
645
645
raise REXML ::ParseException . new ( message , @source )
646
646
end
647
- if @document_status . nil? and match_data [ 1 ] == "xml"
647
+ if match_data [ 1 ] == "xml"
648
+ if @document_status
649
+ raise ParseException . new ( "Malformed XML: XML declaration is not at the start" , @source )
650
+ end
648
651
content = match_data [ 2 ]
649
652
version = VERSION . match ( content )
650
653
version = version [ 1 ] unless version . nil?
Original file line number Diff line number Diff line change @@ -39,6 +39,23 @@ def test_garbage_text
39
39
pi . content ,
40
40
] )
41
41
end
42
+
43
+ def test_xml_declaration_not_at_document_start
44
+ exception = assert_raise ( REXML ::ParseException ) do
45
+ parser = REXML ::Parsers ::BaseParser . new ( '<a><?xml version="1.0" ?></a>' )
46
+ while parser . has_next?
47
+ parser . pull
48
+ end
49
+ end
50
+
51
+ assert_equal ( <<~DETAIL . chomp , exception . to_s )
52
+ Malformed XML: XML declaration is not at the start
53
+ Line: 1
54
+ Position: 25
55
+ Last 80 unconsumed characters:
56
+
57
+ DETAIL
58
+ end
42
59
end
43
60
44
61
def test_after_root
You can’t perform that action at this time.
0 commit comments