@@ -4,11 +4,11 @@ use crate::core::DocContext;
4
4
use crate :: fold:: DocFolder ;
5
5
use crate :: html:: markdown:: opts;
6
6
use core:: ops:: Range ;
7
- use std:: iter:: Peekable ;
8
- use std:: str:: CharIndices ;
9
7
use pulldown_cmark:: { Event , Parser } ;
10
8
use rustc_feature:: UnstableFeatures ;
11
9
use rustc_session:: lint;
10
+ use std:: iter:: Peekable ;
11
+ use std:: str:: CharIndices ;
12
12
13
13
pub const CHECK_INVALID_HTML_TAGS : Pass = Pass {
14
14
name : "check-invalid-html-tags" ,
@@ -104,8 +104,7 @@ fn extract_html_tag(
104
104
tag_name. push ( c) ;
105
105
} else {
106
106
if !tag_name. is_empty ( ) {
107
- let mut r =
108
- Range { start : range. start + start_pos, end : range. start + pos } ;
107
+ let mut r = Range { start : range. start + start_pos, end : range. start + pos } ;
109
108
if c == '>' {
110
109
// In case we have a tag without attribute, we can consider the span to
111
110
// refer to it fully.
@@ -143,6 +142,27 @@ fn extract_html_tag(
143
142
}
144
143
}
145
144
145
+ fn extract_html_comment (
146
+ text : & str ,
147
+ range : & Range < usize > ,
148
+ start_pos : usize ,
149
+ iter : & mut Peekable < CharIndices < ' _ > > ,
150
+ f : & impl Fn ( & str , & Range < usize > ) ,
151
+ ) {
152
+ // We first skip the "!--" part.
153
+ let mut iter = iter. skip ( 3 ) ;
154
+ while let Some ( ( pos, c) ) = iter. next ( ) {
155
+ if c == '-' && text[ pos..] . starts_with ( "-->" ) {
156
+ // All good, we can leave!
157
+ return ;
158
+ }
159
+ }
160
+ f (
161
+ "Unclosed HTML comment" ,
162
+ & Range { start : range. start + start_pos, end : range. start + start_pos + 3 } ,
163
+ ) ;
164
+ }
165
+
146
166
fn extract_tags (
147
167
tags : & mut Vec < ( String , Range < usize > ) > ,
148
168
text : & str ,
@@ -153,7 +173,11 @@ fn extract_tags(
153
173
154
174
while let Some ( ( start_pos, c) ) = iter. next ( ) {
155
175
if c == '<' {
156
- extract_html_tag ( tags, text, & range, start_pos, & mut iter, f) ;
176
+ if text[ start_pos..] . starts_with ( "<!--" ) {
177
+ extract_html_comment ( text, & range, start_pos, & mut iter, f) ;
178
+ } else {
179
+ extract_html_tag ( tags, text, & range, start_pos, & mut iter, f) ;
180
+ }
157
181
}
158
182
}
159
183
}
0 commit comments