From 7e329830681aa8db41e7fda664515aa472badb40 Mon Sep 17 00:00:00 2001 From: lovebaihezi Date: Fri, 30 Dec 2022 15:56:41 +0800 Subject: [PATCH] accept illegal close tag --- src/parser/base.rs | 15 +++++++++++---- src/tests.rs | 11 +++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/parser/base.rs b/src/parser/base.rs index 7b8c498..b83b8cc 100644 --- a/src/parser/base.rs +++ b/src/parser/base.rs @@ -118,8 +118,7 @@ impl<'a> Parser<'a> { // If we do not find any characters that are not identifiers // then we are probably at the end of the stream - let end = simd::search_non_ident(bytes) - .unwrap_or_else(|| self.stream.len() - start); + let end = simd::search_non_ident(bytes).unwrap_or_else(|| self.stream.len() - start); self.stream.idx += end; Some(self.stream.slice(start, start + end)) @@ -219,10 +218,18 @@ impl<'a> Parser<'a> { self.stream.advance(); let closing_tag_name = self.read_to(b'>'); - + + let closing_tag_name = if let Some(end) = simd::find(closing_tag_name, b' ') { + &closing_tag_name[0..end] + } else { + closing_tag_name + }; + self.stream.expect_and_skip_cond(b'>'); - let closing_tag_matches_parent = self.stack.last() + let closing_tag_matches_parent = self + .stack + .last() .and_then(|last_handle| last_handle.get(self)) .and_then(|last_item| last_item.as_tag()) .map_or(false, |last_tag| last_tag.name() == closing_tag_name); diff --git a/src/tests.rs b/src/tests.rs index 8fa4bc8..1d19171 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -739,3 +739,14 @@ fn tag_raw_abrupt_stop() { let from_raw = first_tag.raw().try_as_utf8_str().unwrap(); assert_eq!(from_raw, "

abcd