Skip to content

Commit 72d3fb0

Browse files
committed
HTML API: Prevent bookmark exhaustion from throwing.
When bookmark exhaustion occurs during processing, return `false` instead of throwing an `Exception`. Developed in WordPress/wordpress-develop#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
1 parent 9e1e691 commit 72d3fb0

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

wp-includes/html-api/class-wp-html-processor.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,17 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool {
10421042
$token_name = $this->get_token_name();
10431043

10441044
if ( self::REPROCESS_CURRENT_NODE !== $node_to_process ) {
1045+
try {
1046+
$bookmark_name = $this->bookmark_token();
1047+
} catch ( Exception $e ) {
1048+
if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->last_error ) {
1049+
return false;
1050+
}
1051+
throw $e;
1052+
}
1053+
10451054
$this->state->current_token = new WP_HTML_Token(
1046-
$this->bookmark_token(),
1055+
$bookmark_name,
10471056
$token_name,
10481057
$this->has_self_closing_flag(),
10491058
$this->release_internal_bookmark_on_destruct
@@ -1153,6 +1162,12 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool {
11531162
* otherwise might involve messier calling and return conventions.
11541163
*/
11551164
return false;
1165+
} catch ( Exception $e ) {
1166+
if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->last_error ) {
1167+
return false;
1168+
}
1169+
// Rethrow any other exceptions for higher-level handling.
1170+
throw $e;
11561171
}
11571172
}
11581173

@@ -6315,6 +6330,8 @@ private function insert_foreign_element( WP_HTML_Token $token, bool $only_add_to
63156330
*
63166331
* @since 6.7.0
63176332
*
6333+
* @throws Exception When unable to allocate a bookmark for the next token in the input HTML document.
6334+
*
63186335
* @param string $token_name Name of token to create and insert into the stack of open elements.
63196336
* @param string|null $bookmark_name Optional. Name to give bookmark for created virtual node.
63206337
* Defaults to auto-creating a bookmark name.

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '7.0-beta2-61754';
19+
$wp_version = '7.0-beta2-61755';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)