From bcbb048762c37d7da4bee76be89f6d1b9291d38a Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Tue, 7 Jul 2020 21:08:15 +1000 Subject: [PATCH] Fix not writing closing tag on encoded '<' in content --- src/unit/content.rs | 54 +++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/unit/content.rs b/src/unit/content.rs index 1c6487b..93972c5 100644 --- a/src/unit/content.rs +++ b/src/unit/content.rs @@ -26,13 +26,6 @@ enum ContentType { } impl ContentType { - fn is_tag(&self) -> bool { - match self { - ContentType::Tag => true, - _ => false, - } - } - fn peek(proc: &mut Processor) -> ContentType { // Manually write out matching for fast performance as this is hot spot; don't use generated trie. match proc.peek(0) { @@ -64,7 +57,8 @@ pub fn process_content(proc: &mut Processor, ns: Namespace, parent: Option { @@ -82,29 +76,27 @@ pub fn process_content(proc: &mut Processor, ns: Namespace, parent: Option {} }; - let next_is_decoded_chevron = maybe_normalise_entity(proc) && proc.peek(0).filter(|c| *c == b'<').is_some(); + maybe_normalise_entity(proc); if handle_ws { - // If any of these arms match, this is the start or part of one or more whitespace characters. - // Simply ignore and process until first non-whitespace. - if match next_content_type { - ContentType::Text => proc.m(IsPred(is_whitespace), Discard).nonempty(), - _ => false, - } { + if next_content_type == ContentType::Text && proc.m(IsPred(is_whitespace), Discard).nonempty() { + // This is the start or part of one or more whitespace characters. + // Simply ignore and process until first non-whitespace. ws_skipped = true; continue; }; // Next character is not whitespace, so handle any previously ignored whitespace. if ws_skipped { - if destroy_whole && last_written.is_tag() && next_content_type.is_tag() { + if destroy_whole && last_written == ContentType::Tag && next_content_type == ContentType::Tag { // Whitespace is between two tags, instructions, or bangs. // `destroy_whole` is on, so don't write it. } else if trim && (last_written == ContentType::Start || next_content_type == ContentType::End) { // Whitespace is leading or trailing. // `trim` is on, so don't write it. } else if collapse { - // If writing space, then prev_sibling_closing_tag no longer represents immediate previous sibling node; space will be new previous sibling node (as a text node). + // If writing space, then prev_sibling_closing_tag no longer represents immediate previous sibling + // node; space will be new previous sibling node (as a text node). prev_sibling_closing_tag.write_if_exists(proc); // Current contiguous whitespace needs to be reduced to a single space character. proc.write(b' '); @@ -118,19 +110,6 @@ pub fn process_content(proc: &mut Processor, ns: Namespace, parent: Option b"<", - _ => b"<", - }; - proc.write_slice(encoded); - proc.skip_expect(); - continue; - }; - // Process and consume next character(s). match next_content_type { ContentType::Tag => { @@ -153,7 +132,20 @@ pub fn process_content(proc: &mut Processor, ns: Namespace, parent: Option b"<", + // Use "<" instead of "<" as there are other entity names starting with "lt". + _ => b"<", + }); + proc.skip_expect(); + } else { + proc.accept()?; + }; } _ => unreachable!(), };