Skip to content

Commit

Permalink
Implement remaining "in select" tags
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Jan 21, 2024
1 parent 20e70a4 commit 68609de
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ private function step_in_body() {
*
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-inbody
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inselect
* @see WP_HTML_Processor::step
*
* @return bool Whether an element was found.
Expand All @@ -1163,6 +1163,16 @@ private function step_in_select() {
$op = "{$op_sigil}{$tag_name}";

switch ( $op ) {
/*
* > A start tag whose tag name is "html"
*/
case '+HTML':
$this->last_error = self::ERROR_UNSUPPORTED;
throw new WP_HTML_Unsupported_Exception( "Cannot process {$tag_name} element." );

/*
* > A start tag whose tag name is "option"
*/
case '+OPTION':
$current_node = $this->state->stack_of_open_elements->current_node();
if ( $current_node && 'OPTION' === $current_node->node_name ) {
Expand All @@ -1171,7 +1181,12 @@ private function step_in_select() {
$this->insert_html_element( $this->state->current_token );
return true;

/*
* > A start tag whose tag name is "optgroup"
* > A start tag whose tag name is "hr"
*/
case '+OPTGROUP':
case '+HR':
$current_node = $this->state->stack_of_open_elements->current_node();
if ( $current_node && 'OPTION' === $current_node->node_name ) {
$this->state->stack_of_open_elements->pop();
Expand All @@ -1186,6 +1201,9 @@ private function step_in_select() {
$this->insert_html_element( $this->state->current_token );
return true;

/*
* > An end tag whose tag name is "optgroup"
*/
case '-OPTGROUP':
$walker = $this->state->stack_of_open_elements->walk_up();
$current_node = $walker->current();
Expand All @@ -1206,6 +1224,9 @@ private function step_in_select() {
}
return $this->step();

/*
* > An end tag whose tag name is "option"
*/
case '-OPTION':
$current_node = $this->state->stack_of_open_elements->current_node();
if ( $current_node && 'OPTION' === $current_node->node_name ) {
Expand All @@ -1214,7 +1235,12 @@ private function step_in_select() {
}
return $this->step();

/*
* > An end tag whose tag name is "select"
* > A start tag whose tag name is "select"
*/
case '-SELECT':
case '+SELECT':
if ( ! $this->state->stack_of_open_elements->has_element_in_select_scope( 'SELECT' ) ) {
return $this->step();
}
Expand Down

0 comments on commit 68609de

Please sign in to comment.