From eb626135206b4efd73f83520a07c05e3a2edc12a Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 16 Oct 2024 15:33:59 -0400 Subject: [PATCH] Implement the latest select parsing changes - https://github.com/whatwg/html/pull/10557 - https://github.com/html5lib/html5lib-tests/pull/178 --- gumbo-parser/src/insertion_mode.h | 2 - gumbo-parser/src/parser.c | 240 +++++------------------------- test/html5lib-tests | 2 +- 3 files changed, 37 insertions(+), 207 deletions(-) diff --git a/gumbo-parser/src/insertion_mode.h b/gumbo-parser/src/insertion_mode.h index 6cb1d341f0a..b60054e40b7 100644 --- a/gumbo-parser/src/insertion_mode.h +++ b/gumbo-parser/src/insertion_mode.h @@ -20,8 +20,6 @@ typedef enum { GUMBO_INSERTION_MODE_IN_TABLE_BODY, GUMBO_INSERTION_MODE_IN_ROW, GUMBO_INSERTION_MODE_IN_CELL, - GUMBO_INSERTION_MODE_IN_SELECT, - GUMBO_INSERTION_MODE_IN_SELECT_IN_TABLE, GUMBO_INSERTION_MODE_IN_TEMPLATE, GUMBO_INSERTION_MODE_AFTER_BODY, GUMBO_INSERTION_MODE_IN_FRAMESET, diff --git a/gumbo-parser/src/parser.c b/gumbo-parser/src/parser.c index 06f096f8ddb..2a0578bec4f 100644 --- a/gumbo-parser/src/parser.c +++ b/gumbo-parser/src/parser.c @@ -670,21 +670,6 @@ static GumboInsertionMode get_appropriate_insertion_mode ( } switch (node->v.element.tag) { - case GUMBO_TAG_SELECT: { - if (is_last) { - return GUMBO_INSERTION_MODE_IN_SELECT; - } - for (int i = index; i > 0; --i) { - const GumboNode* ancestor = open_elements->data[i]; - if (node_html_tag_is(ancestor, GUMBO_TAG_TEMPLATE)) { - return GUMBO_INSERTION_MODE_IN_SELECT; - } - if (node_html_tag_is(ancestor, GUMBO_TAG_TABLE)) { - return GUMBO_INSERTION_MODE_IN_SELECT_IN_TABLE; - } - } - return GUMBO_INSERTION_MODE_IN_SELECT; - } case GUMBO_TAG_TD: case GUMBO_TAG_TH: if (!is_last) return GUMBO_INSERTION_MODE_IN_CELL; @@ -1610,6 +1595,7 @@ static bool has_open_element(const GumboParser* parser, GumboTag tag) { TAG(TH), \ TAG(MARQUEE), \ TAG(OBJECT), \ + TAG(SELECT), \ TAG(TEMPLATE), \ TAG_MATHML(MI), \ TAG_MATHML(MO), \ @@ -1694,12 +1680,6 @@ static bool has_an_element_in_table_scope(const GumboParser* parser, GumboTag ta return has_an_element_in_specific_scope(parser, 1, &tag, false, &tags); } -// https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-select-scope -static bool has_an_element_in_select_scope(const GumboParser* parser, GumboTag tag) { - static const TagSet tags = {TAG(OPTGROUP), TAG(OPTION)}; - return has_an_element_in_specific_scope(parser, 1, &tag, true, &tags); -} - // https://html.spec.whatwg.org/multipage/parsing.html#generate-implied-end-tags // "exception" is the "element to exclude from the process" listed in the spec. // Pass GUMBO_TAG_LAST to not exclude any of them. @@ -1804,18 +1784,6 @@ static void close_current_cell(GumboParser* parser, const GumboToken* token) { close_table_cell(parser, token, cell_tag); } -// This factors out the "act as if an end tag of tag name 'select' had been -// seen" clause of the spec, since it's referenced in several places. It pops -// all nodes from the stack until the current