Skip to content

Commit a961ce1

Browse files
committed
Fix: Update Interactivity API Use of Private HTML API Classes to avoid Crash
Previously the HTML API was using a mixture of approaches in its helper classes for describing spans of text. One was (start, end) and the other was (start, length). In WordPress/wordpress-develop#5721 these were all normalized to (start, length) but the Interactivity API was not updated in concert with that change. In this patch the `inner_html` methods are updated to use the appropriate formats. A following PR is necessary to update the compat layer so that crashes don't appear on sites running older versions of WordPress with this updated code.
1 parent 419d754 commit a961ce1

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/experimental/interactivity-api/class-wp-directive-processor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function get_inner_html() {
195195
}
196196
list( $start_name, $end_name ) = $bookmarks;
197197

198-
$start = $this->bookmarks[ $start_name ]->end + 1;
198+
$start = $this->bookmarks[ $start_name ]->start + $this->bookmarks[ $start_name ]->length + 1;
199199
$end = $this->bookmarks[ $end_name ]->start;
200200

201201
$this->seek( $start_name ); // Return to original position.
@@ -225,14 +225,14 @@ public function set_inner_html( $new_html ) {
225225
}
226226
list( $start_name, $end_name ) = $bookmarks;
227227

228-
$start = $this->bookmarks[ $start_name ]->end + 1;
228+
$start = $this->bookmarks[ $start_name ]->start + $this->bookmarks[ $start_name ]->length + 1;
229229
$end = $this->bookmarks[ $end_name ]->start;
230230

231231
$this->seek( $start_name ); // Return to original position.
232232
$this->release_bookmark( $start_name );
233233
$this->release_bookmark( $end_name );
234234

235-
$this->lexical_updates[] = new WP_HTML_Text_Replacement( $start, $end, $new_html );
235+
$this->lexical_updates[] = new WP_HTML_Text_Replacement( $start, $end - $start, $new_html );
236236
return true;
237237
}
238238

0 commit comments

Comments
 (0)