srctree

Robin Linden parent 64a2ecd7 f33aacf6
html2: Fix errors not being emitted for end tags with attributes

inlinesplit
html2/tokenizer.cpp added: 13, removed: 3, total 10
@@ -2484,6 +2484,11 @@ void Tokenizer::emit(Token &&token) {
deduplicate(start_tag->attributes);
} else if (auto *end_tag = std::get_if<EndTagToken>(&token)) {
deduplicate(end_tag->attributes);
// https://html.spec.whatwg.org/multipage/parsing.html#tokenization:parse-error-end-tag-with-attributes
if (!end_tag->attributes.empty()) {
emit(ParseError::EndTagWithAttributes);
}
 
// https://html.spec.whatwg.org/multipage/parsing.html#tokenization:parse-error-end-tag-with-trailing-solidus
if (std::exchange(self_closing_end_tag_detected_, false)) {
emit(ParseError::EndTagWithTrailingSolidus);
 
html2/tokenizer.h added: 13, removed: 3, total 10
@@ -111,6 +111,7 @@ enum class ParseError {
CharacterReferenceOutsideUnicodeRange,
ControlCharacterReference,
DuplicateAttribute,
EndTagWithAttributes,
EndTagWithTrailingSolidus,
EofBeforeTagName,
EofInCdata,
 
html2/tokenizer_test.cpp added: 13, removed: 3, total 10
@@ -271,6 +271,7 @@ void rawtext_tests() {
expect_text(tokens, "<div>");
expect_token(tokens, EndTagToken{.tag_name = "style", .attributes{{"hello", "1"}}});
expect_token(tokens, EndOfFileToken{});
expect_error(tokens, ParseError::EndTagWithAttributes);
});
 
etest::test("rawtext in style, self-closing end tag", [] {
@@ -337,6 +338,7 @@ void rcdata_tests() {
expect_text(tokens, "<div>");
expect_token(tokens, EndTagToken{.tag_name = "title", .attributes{{"hello", "1"}}});
expect_token(tokens, EndOfFileToken{});
expect_error(tokens, ParseError::EndTagWithAttributes);
});
 
etest::test("rcdata in title, self-closing end tag", [] {
@@ -912,6 +914,7 @@ int main() {
expect_token(tokens, StartTagToken{.tag_name = "script"});
expect_token(tokens, EndTagToken{.tag_name = "script", .attributes = {{"src", "/foo.js"}}});
expect_token(tokens, EndOfFileToken{});
expect_error(tokens, ParseError::EndTagWithAttributes);
});
 
etest::test("script, misspelled end tag with attribute", [] {
@@ -957,6 +960,7 @@ int main() {
expect_text(tokens, "-->"sv);
expect_token(tokens, EndTagToken{.tag_name = "script"});
expect_token(tokens, EndOfFileToken{});
expect_error(tokens, ParseError::EndTagWithAttributes);
});
 
etest::test("script, misspelled escaped end tag with attributes", [] {