srctree

Robin Linden parent 67fc1610 8b7e5d2e
html2: Fix deduplication of three or more consecutive duplicate attrs

Issue found by the html5lib tests.

inlinesplit
html2/tokenizer.cpp added: 11, removed: 2, total 9
@@ -2474,6 +2474,7 @@ void Tokenizer::emit(Token &&token) {
for (std::size_t j = i + 1; j < attrs.size(); ++j) {
if (attrs[j].name == name) {
attrs.erase(attrs.begin() + j);
j -= 1;
}
}
}
 
html2/tokenizer_test.cpp added: 11, removed: 2, total 9
@@ -543,6 +543,14 @@ void attribute_name_tests() {
expect_token(tokens, StartTagToken{.tag_name = "p", .attributes{{"a", "1"}}});
expect_token(tokens, EndOfFileToken{});
});
 
etest::test("attribute name: many duplicate attributes", [] {
auto tokens = run_tokenizer("<p a=1 a=2 a=3>");
expect_error(tokens, ParseError::DuplicateAttribute);
expect_error(tokens, ParseError::DuplicateAttribute);
expect_token(tokens, StartTagToken{.tag_name = "p", .attributes{{"a", "1"}}});
expect_token(tokens, EndOfFileToken{});
});
}
 
void after_attribute_name_tests() {