Skip to content

Commit

Permalink
Update HTML tests
Browse files Browse the repository at this point in the history
Update to the latest version of html5lib-tests. The spec currently has a
[bug](whatwg/html#6808) so the parser does not
conform to the spec, but it does match Safari, Firefox, Chrome, and the
html5lib-tests tests.
  • Loading branch information
stevecheckoway committed Jun 29, 2021
1 parent b317bb8 commit e4b29a4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
8 changes: 7 additions & 1 deletion gumbo-parser/src/parser.c
Expand Up @@ -4437,7 +4437,13 @@ static void handle_in_foreign_content(GumboParser* parser, GumboToken* token) {
) {
pop_current_node(parser);
}
handle_in_body(parser, token);
// XXX: The spec currently says to handle this using the in body insertion
// mode rules. That seems wrong. See
// <https://github.com/whatwg/html/issues/6808>. Instead, use the current
// insertion mode which seems like it works.
//
// handle_in_body(parser, token);
handle_html_content(parser, token);
return;
}

Expand Down
72 changes: 72 additions & 0 deletions gumbo-parser/test/parser.cc
Expand Up @@ -2240,4 +2240,76 @@ TEST_F(GumboParserTest, ForeignFragment) {
ASSERT_EQ(GUMBO_NAMESPACE_SVG, foo->v.element.tag_namespace);
}

TEST_F(GumboParserTest, FosterParenting) {
Parse("<!doctype><body><table><colgroup><svg><g>foo</g><g>bar</g><p>baz</table><p>quux");
EXPECT_EQ(1, GetChildCount(root_));
GumboNode* html = GetChild(root_, 0);
ASSERT_EQ(GUMBO_NODE_ELEMENT, html->type);
EXPECT_EQ(GUMBO_TAG_HTML, html->v.element.tag);
EXPECT_EQ(2, GetChildCount(html));

GumboNode* body = GetChild(html, 1);
ASSERT_EQ(GUMBO_NODE_ELEMENT, body->type);
EXPECT_EQ(GUMBO_TAG_BODY, body->v.element.tag);
EXPECT_EQ(4, GetChildCount(body));

GumboNode* svg = GetChild(body, 0);
ASSERT_EQ(GUMBO_NODE_ELEMENT, svg->type);
EXPECT_EQ(GUMBO_TAG_SVG, svg->v.element.tag);
EXPECT_EQ(GUMBO_NAMESPACE_SVG, svg->v.element.tag_namespace);
EXPECT_EQ(2, GetChildCount(svg));

GumboNode* g = GetChild(svg, 0);
ASSERT_EQ(GUMBO_NODE_ELEMENT, g->type);
EXPECT_EQ(std::string("g"), g->v.element.name);
EXPECT_EQ(GUMBO_NAMESPACE_SVG, g->v.element.tag_namespace);
EXPECT_EQ(1, GetChildCount(g));

GumboNode* text = GetChild(g, 0);
ASSERT_EQ(GUMBO_NODE_TEXT, text->type);
EXPECT_EQ(std::string("foo"), text->v.text.text);

g = GetChild(svg, 1);
ASSERT_EQ(GUMBO_NODE_ELEMENT, g->type);
EXPECT_EQ(std::string("g"), g->v.element.name);
EXPECT_EQ(GUMBO_NAMESPACE_SVG, g->v.element.tag_namespace);
EXPECT_EQ(1, GetChildCount(g));

text = GetChild(g, 0);
ASSERT_EQ(GUMBO_NODE_TEXT, text->type);
EXPECT_EQ(std::string("bar"), text->v.text.text);

GumboNode* p = GetChild(body, 1);
ASSERT_EQ(GUMBO_NODE_ELEMENT, p->type);
EXPECT_EQ(GUMBO_TAG_P, p->v.element.tag);
EXPECT_EQ(GUMBO_NAMESPACE_HTML, p->v.element.tag_namespace);
EXPECT_EQ(1, GetChildCount(p));

text = GetChild(p, 0);
ASSERT_EQ(GUMBO_NODE_TEXT, text->type);
EXPECT_EQ(std::string("baz"), text->v.text.text);

GumboNode* table = GetChild(body, 2);
ASSERT_EQ(GUMBO_NODE_ELEMENT, table->type);
EXPECT_EQ(GUMBO_TAG_TABLE, table->v.element.tag);
EXPECT_EQ(GUMBO_NAMESPACE_HTML, table->v.element.tag_namespace);
EXPECT_EQ(1, GetChildCount(table));

GumboNode* colgroup = GetChild(table, 0);
ASSERT_EQ(GUMBO_NODE_ELEMENT, colgroup->type);
EXPECT_EQ(GUMBO_TAG_COLGROUP, colgroup->v.element.tag);
EXPECT_EQ(GUMBO_NAMESPACE_HTML, colgroup->v.element.tag_namespace);
EXPECT_EQ(0, GetChildCount(colgroup));

p = GetChild(body, 3);
ASSERT_EQ(GUMBO_NODE_ELEMENT, p->type);
EXPECT_EQ(GUMBO_TAG_P, p->v.element.tag);
EXPECT_EQ(GUMBO_NAMESPACE_HTML, p->v.element.tag_namespace);
EXPECT_EQ(1, GetChildCount(p));

text = GetChild(p, 0);
ASSERT_EQ(GUMBO_NODE_TEXT, text->type);
EXPECT_EQ(std::string("quux"), text->v.text.text);
}

} // namespace

0 comments on commit e4b29a4

Please sign in to comment.