srctree

Robin Linden parent ce5592f1 4c2f55e8
html2: Fix errors not being emitted for self-closing end tags

inlinesplit
html2/tokenizer.cpp added: 16, removed: 6, total 10
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -2484,7 +2484,12 @@ 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-trailing-solidus
if (end_tag->self_closing) {
emit(ParseError::EndTagWithTrailingSolidus);
}
}
 
on_emit_(*this, std::move(token));
}
 
 
html2/tokenizer.h added: 16, removed: 6, total 10
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -111,6 +111,7 @@ enum class ParseError {
CharacterReferenceOutsideUnicodeRange,
ControlCharacterReference,
DuplicateAttribute,
EndTagWithTrailingSolidus,
EofBeforeTagName,
EofInCdata,
EofInComment,
 
html2/tokenizer_test.cpp added: 16, removed: 6, total 10
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -279,6 +279,7 @@ void rawtext_tests() {
expect_text(tokens, "<div>");
expect_token(tokens, EndTagToken{.tag_name = "style", .self_closing = true});
expect_token(tokens, EndOfFileToken{});
expect_error(tokens, ParseError::EndTagWithTrailingSolidus);
});
 
etest::test("rawtext, end tag open, eof", [] {
@@ -344,6 +345,7 @@ void rcdata_tests() {
expect_text(tokens, "<div>");
expect_token(tokens, EndTagToken{.tag_name = "title", .self_closing = true});
expect_token(tokens, EndOfFileToken{});
expect_error(tokens, ParseError::EndTagWithTrailingSolidus);
});
 
etest::test("rcdata, end tag open, eof", [] {
@@ -926,6 +928,7 @@ int main() {
expect_token(tokens, StartTagToken{.tag_name = "script"});
expect_token(tokens, EndTagToken{.tag_name = "script", .self_closing = true});
expect_token(tokens, EndOfFileToken{});
expect_error(tokens, ParseError::EndTagWithTrailingSolidus);
});
 
etest::test("script, misspelled self closing end tag", [] {
@@ -974,6 +977,7 @@ int main() {
expect_text(tokens, "-->"sv);
expect_token(tokens, EndTagToken{.tag_name = "script"});
expect_token(tokens, EndOfFileToken{});
expect_error(tokens, ParseError::EndTagWithTrailingSolidus);
});
 
etest::test("script, misspelled escaped self closing end tag", [] {