File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ impl Default for SerializeOpts {
37
37
}
38
38
}
39
39
40
+ #[ derive( Default ) ]
40
41
struct ElemInfo {
41
42
html_name : Option < LocalName > ,
42
43
ignore_children : bool ,
@@ -66,16 +67,16 @@ impl<Wr: Write> HtmlSerializer<Wr> {
66
67
HtmlSerializer {
67
68
writer : writer,
68
69
opts : opts,
69
- stack : vec ! ( ElemInfo {
70
- html_name: None ,
71
- ignore_children: false ,
72
- processed_first_child: false ,
73
- } ) ,
70
+ stack : vec ! [ Default :: default ( ) ] ,
74
71
}
75
72
}
76
73
77
74
fn parent ( & mut self ) -> & mut ElemInfo {
78
- self . stack . last_mut ( ) . expect ( "no parent ElemInfo" )
75
+ if self . stack . len ( ) == 0 {
76
+ warn ! ( "ElemInfo stack empty, creating new parent" ) ;
77
+ self . stack . push ( Default :: default ( ) ) ;
78
+ }
79
+ self . stack . last_mut ( ) . unwrap ( )
79
80
}
80
81
81
82
fn write_escaped ( & mut self , text : & str , attr_mode : bool ) -> io:: Result < ( ) > {
@@ -159,7 +160,10 @@ impl<Wr: Write> Serializer for HtmlSerializer<Wr> {
159
160
}
160
161
161
162
fn end_elem ( & mut self , name : QualName ) -> io:: Result < ( ) > {
162
- let info = self . stack . pop ( ) . expect ( "no ElemInfo" ) ;
163
+ let info = self . stack . pop ( ) . unwrap_or_else ( || {
164
+ warn ! ( "missing ElemInfo, creating default." ) ;
165
+ Default :: default ( )
166
+ } ) ;
163
167
if info. ignore_children {
164
168
return Ok ( ( ) ) ;
165
169
}
You can’t perform that action at this time.
0 commit comments