@@ -337,38 +337,38 @@ impl ReaderState {
337337 debug_assert ! ( content. starts_with( b"<!--" ) , "{:?}" , Bytes ( content) ) ;
338338 debug_assert ! ( content. ends_with( b"-->" ) , "{:?}" , Bytes ( content) ) ;
339339
340- let buf = & content[ 1 ..content. len ( ) - 1 ] ;
341- let len = buf. len ( ) ;
340+ let len = content. len ( ) ;
342341 if self . config . check_comments {
343342 // search if '--' not in comments
344- let mut haystack = & buf[ 3 ..len - 2 ] ;
343+ // Skip `<!--` and `-->`
344+ let mut haystack = & content[ 4 ..len - 3 ] ;
345345 let mut off = 0 ;
346346 while let Some ( p) = memchr:: memchr ( b'-' , haystack) {
347347 off += p + 1 ;
348348 // if next byte after `-` is also `-`, return an error
349- if buf [ 3 + off] == b'-' {
349+ if content [ 4 + off] == b'-' {
350350 // Explanation of the magic:
351351 //
352352 // - `self.offset`` just after `>`,
353353 // - `buf` contains `!-- con--tent --`
354354 // - `p` is counted from byte after `<!--`
355355 //
356356 // <!-- con--tent -->:
357- // ~~~~~~~~~~~~~~~~ : - buf
357+ // ~~~~~~~~~~~~~~~~~~ : - buf
358358 // : =========== : - zone of search (possible values of `p`)
359359 // : |---p : - p is counted from | (| is 0)
360360 // : : : ^ - self.offset
361- // ^ : : - self.offset - len
362- // ^ : - self.offset - len + 2
363- // ^ - self.offset - len + 2 + p
364- self . last_error_offset = self . offset - len + 2 + p;
361+ // ^ : : - self.offset - len
362+ // ^ : - self.offset - len + 4
363+ // ^ - self.offset - len + 4 + p
364+ self . last_error_offset = self . offset - len + 4 + p;
365365 return Err ( Error :: IllFormed ( IllFormedError :: DoubleHyphenInComment ) ) ;
366366 }
367367 haystack = & haystack[ p + 1 ..] ;
368368 }
369369 }
370370 Ok ( Event :: Comment ( BytesText :: wrap (
371- & buf [ 3 ..len - 2 ] ,
371+ & content [ 4 ..len - 3 ] ,
372372 self . decoder ( ) ,
373373 ) ) )
374374 }
@@ -381,10 +381,10 @@ impl ReaderState {
381381 ) ;
382382 debug_assert ! ( content. ends_with( b">" ) , "{:?}" , Bytes ( content) ) ;
383383
384- let buf = & content[ 1 ..content. len ( ) - 1 ] ;
385- match buf[ 8 .. ] . iter ( ) . position ( |& b| !is_whitespace ( b) ) {
384+ let buf = & content[ 9 ..content. len ( ) - 1 ] ;
385+ match buf. iter ( ) . position ( |& b| !is_whitespace ( b) ) {
386386 Some ( start) => Ok ( Event :: DocType ( BytesText :: wrap (
387- & buf[ 8 + start..] ,
387+ & buf[ start..] ,
388388 self . decoder ( ) ,
389389 ) ) ) ,
390390 None => {
0 commit comments