From e4b29a43ed53454c2db457d8db6835d1cce45566 Mon Sep 17 00:00:00 2001 From: Stephen Checkoway Date: Sat, 26 Jun 2021 18:24:59 -0400 Subject: [PATCH] Update HTML tests Update to the latest version of html5lib-tests. The spec currently has a [bug](https://github.com/whatwg/html/issues/6808) so the parser does not conform to the spec, but it does match Safari, Firefox, Chrome, and the html5lib-tests tests. --- gumbo-parser/src/parser.c | 8 ++++- gumbo-parser/test/parser.cc | 72 +++++++++++++++++++++++++++++++++++++ test/html5lib-tests | 2 +- 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/gumbo-parser/src/parser.c b/gumbo-parser/src/parser.c index e58b05ac19..b68443d92c 100644 --- a/gumbo-parser/src/parser.c +++ b/gumbo-parser/src/parser.c @@ -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 + // . Instead, use the current + // insertion mode which seems like it works. + // + // handle_in_body(parser, token); + handle_html_content(parser, token); return; } diff --git a/gumbo-parser/test/parser.cc b/gumbo-parser/test/parser.cc index 33a4f2bae6..0832f919de 100644 --- a/gumbo-parser/test/parser.cc +++ b/gumbo-parser/test/parser.cc @@ -2240,4 +2240,76 @@ TEST_F(GumboParserTest, ForeignFragment) { ASSERT_EQ(GUMBO_NAMESPACE_SVG, foo->v.element.tag_namespace); } +TEST_F(GumboParserTest, FosterParenting) { + Parse("foobar

baz

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 diff --git a/test/html5lib-tests b/test/html5lib-tests index e379d7a17b..535e74b475 160000 --- a/test/html5lib-tests +++ b/test/html5lib-tests @@ -1 +1 @@ -Subproject commit e379d7a17b18cd1bb57aec4f62edec67578d294a +Subproject commit 535e74b4759d94fdc4038d2da9d6b70da6287614