From 6ab687c73795b899b3ab0e8b8e9a12c5377553db Mon Sep 17 00:00:00 2001 From: Kirsten Laskoski Date: Sun, 28 Apr 2024 13:45:37 -0400 Subject: [PATCH] Handle whitespace inside closing tags Fixes #65 by adding a skip whitespace before and after the name of a closing tag. Also adds a test to verify that this functions properly, based on the example in #65. Note that the [HTML spec] does not allow for whitespace between the ` Parser<'a> { fn read_end(&mut self) { self.stream.advance(); + self.skip_whitespaces(); - let closing_tag_name = self.read_to(b'>'); - - self.stream.expect_and_skip_cond(b'>'); + if let Some(closing_tag_name) = self.read_ident() { + self.skip_whitespaces(); + self.stream.expect_and_skip_cond(b'>'); - 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); + 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); - if !closing_tag_matches_parent { + if !closing_tag_matches_parent { + return; + } + } else { return; } diff --git a/src/tests.rs b/src/tests.rs index 046861a..ecf2fe5 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,4 +1,4 @@ -use crate::{parse, parse_owned, Bytes}; +use crate::{parse, parse_owned, Bytes, VDom}; use crate::{parser::*, HTMLTag, Node}; fn force_as_tag<'a, 'b>(actual: &'a Node<'b>) -> &'a HTMLTag<'b> { @@ -778,3 +778,34 @@ fn tag_raw_abrupt_stop() { let from_raw = first_tag.raw().try_as_utf8_str().unwrap(); assert_eq!(from_raw, "

abcd