File tree 4 files changed +5
-16
lines changed
4 files changed +5
-16
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,10 @@ def pull_event
249
249
if @document_status == :in_doctype
250
250
raise ParseException . new ( "Malformed DOCTYPE: unclosed" , @source )
251
251
end
252
+ unless @tags . empty?
253
+ path = "/" + @tags . join ( "/" )
254
+ raise ParseException . new ( "Missing end tag for '#{ path } '" , @source )
255
+ end
252
256
return [ :end_document ]
253
257
end
254
258
return @stack . shift if @stack . size > 0
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ class StreamParser
7
7
def initialize source , listener
8
8
@listener = listener
9
9
@parser = BaseParser . new ( source )
10
- @tag_stack = [ ]
11
10
end
12
11
13
12
def add_listener ( listener )
@@ -20,21 +19,14 @@ def parse
20
19
event = @parser . pull
21
20
case event [ 0 ]
22
21
when :end_document
23
- unless @tag_stack . empty?
24
- tag_path = "/" + @tag_stack . join ( "/" )
25
- raise ParseException . new ( "Missing end tag for '#{ tag_path } '" ,
26
- @parser . source )
27
- end
28
22
return
29
23
when :start_element
30
- @tag_stack << event [ 1 ]
31
24
attrs = event [ 2 ] . each do |n , v |
32
25
event [ 2 ] [ n ] = @parser . unnormalize ( v )
33
26
end
34
27
@listener . tag_start ( event [ 1 ] , attrs )
35
28
when :end_element
36
29
@listener . tag_end ( event [ 1 ] )
37
- @tag_stack . pop
38
30
when :text
39
31
unnormalized = @parser . unnormalize ( event [ 1 ] )
40
32
@listener . text ( unnormalized )
Original file line number Diff line number Diff line change @@ -15,27 +15,20 @@ def add_listener( listener )
15
15
end
16
16
17
17
def parse
18
- tag_stack = [ ]
19
18
entities = nil
20
19
begin
21
20
while true
22
21
event = @parser . pull
23
22
#STDERR.puts "TREEPARSER GOT #{event.inspect}"
24
23
case event [ 0 ]
25
24
when :end_document
26
- unless tag_stack . empty?
27
- raise ParseException . new ( "No close tag for #{ @build_context . xpath } " ,
28
- @parser . source , @parser )
29
- end
30
25
return
31
26
when :start_element
32
- tag_stack . push ( event [ 1 ] )
33
27
el = @build_context = @build_context . add_element ( event [ 1 ] )
34
28
event [ 2 ] . each do |key , value |
35
29
el . attributes [ key ] = Attribute . new ( key , value , self )
36
30
end
37
31
when :end_element
38
- tag_stack . pop
39
32
@build_context = @build_context . parent
40
33
when :text
41
34
if @build_context [ -1 ] . instance_of? Text
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ def test_no_close_tag
31
31
parse ( xml )
32
32
end
33
33
assert_equal ( <<-MESSAGE , exception . to_s )
34
- No close tag for /root
34
+ Missing end tag for ' /root'
35
35
Line: 1
36
36
Position: #{ xml . bytesize }
37
37
Last 80 unconsumed characters:
You can’t perform that action at this time.
0 commit comments