From 72d3fb0034dbbfcd0a753b3b2cb2e5a9268060aa Mon Sep 17 00:00:00 2001 From: jonsurrell Date: Fri, 27 Feb 2026 13:06:44 +0000 Subject: [PATCH] HTML API: Prevent bookmark exhaustion from throwing. When bookmark exhaustion occurs during processing, return `false` instead of throwing an `Exception`. Developed in https://github.com/WordPress/wordpress-develop/pull/10616. Props jonsurrell, westonruter, dmsnell. Fixes #64394. Built from https://develop.svn.wordpress.org/trunk@61755 git-svn-id: http://core.svn.wordpress.org/trunk@61061 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../html-api/class-wp-html-processor.php | 19 ++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/wp-includes/html-api/class-wp-html-processor.php b/wp-includes/html-api/class-wp-html-processor.php index 8a63353787..f9a449c3c6 100644 --- a/wp-includes/html-api/class-wp-html-processor.php +++ b/wp-includes/html-api/class-wp-html-processor.php @@ -1042,8 +1042,17 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { $token_name = $this->get_token_name(); if ( self::REPROCESS_CURRENT_NODE !== $node_to_process ) { + try { + $bookmark_name = $this->bookmark_token(); + } catch ( Exception $e ) { + if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->last_error ) { + return false; + } + throw $e; + } + $this->state->current_token = new WP_HTML_Token( - $this->bookmark_token(), + $bookmark_name, $token_name, $this->has_self_closing_flag(), $this->release_internal_bookmark_on_destruct @@ -1153,6 +1162,12 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * otherwise might involve messier calling and return conventions. */ return false; + } catch ( Exception $e ) { + if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->last_error ) { + return false; + } + // Rethrow any other exceptions for higher-level handling. + throw $e; } } @@ -6315,6 +6330,8 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.7.0 * + * @throws Exception When unable to allocate a bookmark for the next token in the input HTML document. + * * @param string $token_name Name of token to create and insert into the stack of open elements. * @param string|null $bookmark_name Optional. Name to give bookmark for created virtual node. * Defaults to auto-creating a bookmark name. diff --git a/wp-includes/version.php b/wp-includes/version.php index ffb04ca788..a315c53c95 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '7.0-beta2-61754'; +$wp_version = '7.0-beta2-61755'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.