-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML API: Backport updates from Core, fix Interactivity API
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. this PR also includes the necessary back port of the HTML API to provide the new methods so that older WP installs don’t crash
- Loading branch information
Showing
6 changed files
with
2,727 additions
and
4 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
lib/compat/wordpress-6.5/html-api/class-gutenberg-html-attribute-token-6-5.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* HTML API: WP_HTML_Attribute_Token class | ||
* | ||
* @package WordPress | ||
* @subpackage HTML-API | ||
* @since 6.2.0 | ||
*/ | ||
|
||
/** | ||
* Core class used by the HTML tag processor as a data structure for the attribute token, | ||
* allowing to drastically improve performance. | ||
* | ||
* This class is for internal usage of the WP_HTML_Tag_Processor class. | ||
* | ||
* @access private | ||
* @since 6.2.0 | ||
* @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`. | ||
* | ||
* @see WP_HTML_Tag_Processor | ||
*/ | ||
class Gutenberg_HTML_Attribute_Token_6_5 { | ||
/** | ||
* Attribute name. | ||
* | ||
* @since 6.2.0 | ||
* | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* Attribute value. | ||
* | ||
* @since 6.2.0 | ||
* | ||
* @var int | ||
*/ | ||
public $value_starts_at; | ||
|
||
/** | ||
* How many bytes the value occupies in the input HTML. | ||
* | ||
* @since 6.2.0 | ||
* | ||
* @var int | ||
*/ | ||
public $value_length; | ||
|
||
/** | ||
* The string offset where the attribute name starts. | ||
* | ||
* @since 6.2.0 | ||
* | ||
* @var int | ||
*/ | ||
public $start; | ||
|
||
/** | ||
* Byte length of text spanning the attribute inside a tag. | ||
* | ||
* This span starts at the first character of the attribute name | ||
* and it ends after one of three cases: | ||
* | ||
* - at the end of the attribute name for boolean attributes. | ||
* - at the end of the value for unquoted attributes. | ||
* - at the final single or double quote for quoted attributes. | ||
* | ||
* Example: | ||
* | ||
* <div class="post"> | ||
* ------------ length is 12, including quotes | ||
* | ||
* <input type="checked" checked id="selector"> | ||
* ------- length is 6 | ||
* | ||
* <a rel=noopener> | ||
* ------------ length is 11 | ||
* | ||
* @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`. | ||
* | ||
* @var int | ||
*/ | ||
public $length; | ||
|
||
/** | ||
* Whether the attribute is a boolean attribute with value `true`. | ||
* | ||
* @since 6.2.0 | ||
* | ||
* @var bool | ||
*/ | ||
public $is_true; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 6.2.0 | ||
* @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`. | ||
* | ||
* @param string $name Attribute name. | ||
* @param int $value_start Attribute value. | ||
* @param int $value_length Number of bytes attribute value spans. | ||
* @param int $start The string offset where the attribute name starts. | ||
* @param int $length Byte length of the entire attribute name or name and value pair expression. | ||
* @param bool $is_true Whether the attribute is a boolean attribute with true value. | ||
*/ | ||
public function __construct( $name, $value_start, $value_length, $start, $length, $is_true ) { | ||
$this->name = $name; | ||
$this->value_starts_at = $value_start; | ||
$this->value_length = $value_length; | ||
$this->start = $start; | ||
$this->length = $length; | ||
$this->is_true = $is_true; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
lib/compat/wordpress-6.5/html-api/class-gutenberg-html-span-6-5.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* HTML API: WP_HTML_Span class | ||
* | ||
* @package WordPress | ||
* @subpackage HTML-API | ||
* @since 6.2.0 | ||
*/ | ||
|
||
/** | ||
* Core class used by the HTML tag processor to represent a textual span | ||
* inside an HTML document. | ||
* | ||
* This is a two-tuple in disguise, used to avoid the memory overhead | ||
* involved in using an array for the same purpose. | ||
* | ||
* This class is for internal usage of the WP_HTML_Tag_Processor class. | ||
* | ||
* @access private | ||
* @since 6.2.0 | ||
* @since 6.5.0 Replaced `end` with `length` to more closely align with `substr()`. | ||
* | ||
* @see WP_HTML_Tag_Processor | ||
*/ | ||
class Gutenberg_HTML_Span_6_5 { | ||
/** | ||
* Byte offset into document where span begins. | ||
* | ||
* @since 6.2.0 | ||
* | ||
* @var int | ||
*/ | ||
public $start; | ||
|
||
/** | ||
* Byte length of this span. | ||
* | ||
* @since 6.5.0 | ||
* | ||
* @var int | ||
*/ | ||
public $length; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 6.2.0 | ||
* | ||
* @param int $start Byte offset into document where replacement span begins. | ||
* @param int $length Byte length of span. | ||
*/ | ||
public function __construct( $start, $length ) { | ||
$this->start = $start; | ||
$this->length = $length; | ||
} | ||
} |
Oops, something went wrong.
5137da0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 5137da0.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7159507092
📝 Reported issues:
/test/e2e/specs/site-editor/font-library.spec.js