diff --git a/src/wp-includes/html-api/class-wp-html-active-formatting-elements.php b/src/wp-includes/html-api/class-wp-html-active-formatting-elements.php index 90c3bbbd34e3b..d73561843bcb2 100644 --- a/src/wp-includes/html-api/class-wp-html-active-formatting-elements.php +++ b/src/wp-includes/html-api/class-wp-html-active-formatting-elements.php @@ -67,7 +67,7 @@ public function contains_node( WP_HTML_Token $token ) { * * @since 6.4.0 * - * @return int How many node are in the stack of active formatting elements. + * @return int How many nodes are in the stack of active formatting elements. */ public function count() { return count( $this->stack ); diff --git a/src/wp-includes/html-api/class-wp-html-attribute-token.php b/src/wp-includes/html-api/class-wp-html-attribute-token.php index fab66d827b451..3cf93b28905af 100644 --- a/src/wp-includes/html-api/class-wp-html-attribute-token.php +++ b/src/wp-includes/html-api/class-wp-html-attribute-token.php @@ -32,7 +32,7 @@ class WP_HTML_Attribute_Token { public $name; /** - * Attribute value. + * Byte offset in the input HTML where the attribute value starts. * * @since 6.2.0 * @@ -101,7 +101,7 @@ class WP_HTML_Attribute_Token { * @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_start Byte offset where the attribute value starts. * @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. diff --git a/src/wp-includes/html-api/class-wp-html-decoder.php b/src/wp-includes/html-api/class-wp-html-decoder.php index d902f4b7cabc4..0a781a88efc77 100644 --- a/src/wp-includes/html-api/class-wp-html-decoder.php +++ b/src/wp-includes/html-api/class-wp-html-decoder.php @@ -83,7 +83,7 @@ public static function attribute_starts_with( $haystack, $search_text, $case_sen * * Example: * - * 'β€œπŸ˜„β€' === WP_HTML_Decode::decode_text_node( '“😄”' ); + * 'β€œπŸ˜„β€' === WP_HTML_Decoder::decode_text_node( '“😄”' ); * * @since 6.6.0 * @@ -103,7 +103,7 @@ public static function decode_text_node( $text ): string { * * Example: * - * 'β€œπŸ˜„β€' === WP_HTML_Decode::decode_attribute( '“😄”' ); + * 'β€œπŸ˜„β€' === WP_HTML_Decoder::decode_attribute( '“😄”' ); * * @since 6.6.0 * diff --git a/src/wp-includes/html-api/class-wp-html-doctype-info.php b/src/wp-includes/html-api/class-wp-html-doctype-info.php index 1e57afb3fd550..2e21e033babc1 100644 --- a/src/wp-includes/html-api/class-wp-html-doctype-info.php +++ b/src/wp-includes/html-api/class-wp-html-doctype-info.php @@ -138,7 +138,7 @@ class WP_HTML_Doctype_Info { * indicate one of three possible document compatibility modes: * * - "no-quirks" and "limited-quirks" modes (also called "standards" mode). - * - "quirks" mode (also called `CSS1Compat` mode). + * - "quirks" mode (also called `BackCompat` mode). * * An appropriate DOCTYPE is one encountered in the "initial" insertion mode, * before the HTML element has been opened and before finding any other diff --git a/src/wp-includes/html-api/class-wp-html-open-elements.php b/src/wp-includes/html-api/class-wp-html-open-elements.php index 0cd1f0fc45e07..aeee107250895 100644 --- a/src/wp-includes/html-api/class-wp-html-open-elements.php +++ b/src/wp-includes/html-api/class-wp-html-open-elements.php @@ -78,7 +78,7 @@ class WP_HTML_Open_Elements { * Sets a pop handler that will be called when an item is popped off the stack of * open elements. * - * The function will be called with the pushed item as its argument. + * The function will be called with the popped item as its argument. * * @since 6.6.0 * @@ -103,7 +103,7 @@ public function set_push_handler( Closure $handler ): void { } /** - * Returns the name of the node at the nth position on the stack + * Returns the node at the nth position on the stack * of open elements, or `null` if no such position exists. * * Note that this uses a 1-based index, which represents the @@ -114,7 +114,7 @@ public function set_push_handler( Closure $handler ): void { * * @param int $nth Retrieve the nth item on the stack, with 1 being * the top element, 2 being the second, etc... - * @return WP_HTML_Token|null Name of the node on the stack at the given location, + * @return WP_HTML_Token|null The node on the stack at the given location, * or `null` if the location isn't on the stack. */ public function at( int $nth ): ?WP_HTML_Token { @@ -168,7 +168,7 @@ public function contains_node( WP_HTML_Token $token ): bool { * * @since 6.4.0 * - * @return int How many node are in the stack of open elements. + * @return int How many nodes are in the stack of open elements. */ public function count(): int { return count( $this->stack ); diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 35d91fad3129c..f41c828c5b2c0 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -66,7 +66,7 @@ * tags may be found with the shortest-matching breadcrumb query. That is, * `array( 'IMG' )` matches all IMG elements and `array( 'P', 'IMG' )` * matches all IMG elements directly inside a P element. To ensure that no - * partial matches erroneously match it's possible to specify in a query + * partial matches erroneously match, it's possible to specify in a query * the full breadcrumb match all the way down from the root HTML element. * * Example: @@ -341,6 +341,8 @@ public static function create_fragment( $html, $context = '', $encoding = * isn't UTF-8, first convert the document to UTF-8, then pass in the * converted HTML. * + * @since 6.7.0 + * * @param string $html Input HTML document to process. * @param string|null $known_definite_encoding Optional. If provided, specifies the charset used * in the input byte stream. Currently must be UTF-8. @@ -621,7 +623,7 @@ private function bail( string $message ) { * * Various situations lead to parsing failure but this class will * return `false` in all those cases. To determine why something - * failed it's possible to request the last error. This can be + * failed, it's possible to request the last error. This can be * helpful to know to distinguish whether a given tag couldn't * be found or if content in the document caused the processor * to give up and abort processing. @@ -957,7 +959,7 @@ public function matches_breadcrumbs( $breadcrumbs ): bool { * token, or if it will self-close on the next step. * * Most HTML elements expect a closer, such as a P element or - * a DIV element. Others, like an IMG element are void and don't + * a DIV element. Others, like an IMG element, are void and don't * have a closing tag. Special elements, such as SCRIPT and STYLE, * are treated just like void tags. Text nodes and self-closing * foreign content will also act just like a void tag, immediately @@ -1340,7 +1342,7 @@ public function serialize(): ?string { * Serializes the currently-matched token. * * This method produces a fully-normative HTML string for the currently-matched token, - * if able. If not matched at any token or if the token doesn't correspond to any HTML + * if able. If not matched at any token, or if the token doesn't correspond to any HTML, * it will return an empty string (for example, presumptuous end tags are ignored). * * @see static::serialize() @@ -5208,7 +5210,7 @@ private function step_in_foreign_content(): bool { * * @throws Exception When unable to allocate requested bookmark. * - * @return string|false Name of created bookmark, or false if unable to create. + * @return string Name of created bookmark. */ private function bookmark_token() { if ( ! parent::set_bookmark( ++$this->bookmark_counter ) ) { diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 77c1a471db5b1..f11fe9cde5087 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -213,7 +213,7 @@ * * ### Bookmarks * - * While scanning through the input HTMl document it's possible to set + * While scanning through the input HTML document it's possible to set * a named bookmark when a particular tag is found. Later on, after * continuing to scan other tags, it's possible to `seek` to one of * the set bookmarks and then proceed again from that point forward. @@ -286,7 +286,7 @@ * * For these elements the Tag Processor treats the entire sequence as one, * from the opening tag, including its contents, through its closing tag. - * This means that the it's not possible to match the closing tag for a + * This means that it's not possible to match the closing tag for a * SCRIPT element unless it's unexpected; the Tag Processor already matched * it when it found the opening tag. * @@ -298,7 +298,7 @@ * closing the SCRIPT from inside a JavaScript string. E.g. `console.log( '' )`. * - `TITLE` and `TEXTAREA` whose contents are treated as plaintext and then any * character references are decoded. E.g. `1 < 2 < 3` becomes `1 < 2 < 3`. - * - `IFRAME`, `NOSCRIPT`, `NOEMBED`, `NOFRAME`, `STYLE` whose contents are treated as + * - `IFRAME`, `NOEMBED`, `NOFRAMES`, `STYLE` whose contents are treated as * raw plaintext and left as-is. E.g. `1 < 2 < 3` remains `1 < 2 < 3`. * * #### Other tokens with modifiable text. @@ -329,7 +329,7 @@ * and disallows "xml" as a name, since it's special. The Tag Processor only recognizes * target names with an ASCII-representable subset of characters. It also exhibits the * same constraint as with CDATA sections, in that `>` cannot exist within the token - * since Processing Instructions do no exist within HTML and their syntax transforms + * since Processing Instructions do not exist within HTML and their syntax transforms * into a bogus comment in the DOM. * * ## Design and limitations @@ -521,7 +521,7 @@ class WP_HTML_Tag_Processor { * - A TABLE start tag `` implicitly closes any open `P` element. * * - In `QUIRKS_MODE`: - * - CSS class and ID selectors match match in an ASCII case-insensitive manner. + * - CSS class and ID selectors match in an ASCII case-insensitive manner. * - A TABLE start tag `
` opens a `TABLE` element as a child of a `P` * element if one is open. * @@ -614,12 +614,12 @@ class WP_HTML_Tag_Processor { * Example: * *
... - * 012345678901234 - * - token length is 14 - 0 = 14 + * 0123456789012345 + * - token length is 15 - 0 = 15 * * a is a token. * 0123456789 123456789 123456789 - * - token length is 17 - 2 = 15 + * - token length is 18 - 2 = 16 * * @since 6.5.0 * @@ -926,8 +926,6 @@ public function next_tag( $query = null ): bool { * - a DOCTYPE declaration. * - a processing instruction, e.g. ``. * - * The Tag Processor currently only supports the tag token. - * * @since 6.5.0 * @since 6.7.0 Recognizes CDATA sections within foreign content. * @@ -1073,7 +1071,7 @@ private function base_class_next_token(): bool { * * Preserve the opening tag pointers, as these will be overwritten * when finding the closing tag. They will be reset after finding - * the closing to tag to point to the opening of the special atomic + * the closing tag to point to the opening of the special atomic * tag sequence. */ $tag_name_starts_at = $this->tag_name_starts_at; @@ -1149,7 +1147,7 @@ private function base_class_next_token(): bool { * Example: * * $processor = new WP_HTML_Tag_Processor( 'subdivide_text_appropriately(); * - * $processor = new WP_HTML_Tag_Processor( " \r\n\tMore" ); - * true === $processor->next_token(); // Text is "␀ ␀␉More". - * true === $processor->subdivide_text_appropriately(); // Text is "␀ ␀␉". + * $processor = new WP_HTML_Tag_Processor( " \r\n\tMore" ); + * true === $processor->next_token(); // Text is "␍ βŠβ‰More". + * true === $processor->subdivide_text_appropriately(); // Text is "␍ βŠβ‰". * true === $processor->next_token(); // Text is "More". * false === $processor->subdivide_text_appropriately(); * @@ -4935,7 +4933,7 @@ public function get_doctype_info(): ?WP_HTML_Doctype_Info { * * * Funky comments are tag closers with invalid tag names. Note - * that in HTML these are turn into bogus comments. Nonetheless, + * that in HTML these are turned into bogus comments. Nonetheless, * the Tag Processor recognizes them in a stream of HTML and * exposes them for inspection and modification. * diff --git a/src/wp-includes/html-api/class-wp-html-token.php b/src/wp-includes/html-api/class-wp-html-token.php index d5e51ac29007f..d95f2934c5c78 100644 --- a/src/wp-includes/html-api/class-wp-html-token.php +++ b/src/wp-includes/html-api/class-wp-html-token.php @@ -29,7 +29,7 @@ class WP_HTML_Token { * * @since 6.4.0 * - * @var string + * @var string|null */ public $bookmark_name = null; diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php b/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php index e516addb6c314..52a855d40cff4 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php @@ -138,7 +138,7 @@ public function test_unexpected_closing_tags_are_removed() { $this->assertSame( WP_HTML_Processor::normalize( 'one
twothree' ), 'onetwothree', - 'Should have removed unpected closing tags.' + 'Should have removed unexpected closing tags.' ); } diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index a89014282df73..bb18629563493 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -1071,11 +1071,11 @@ public function test_ensure_next_token_method_extensibility( $html, $expected_to * @ticket 62427 */ public function test_next_tag_lowercase_tag_name() { - // The upper case
is irrelevant but illustrates the case-insentivity. + // The upper case
is irrelevant but illustrates the case-insensitivity. $processor = WP_HTML_Processor::create_fragment( '
' ); $this->assertTrue( $processor->next_tag( array( 'tag_name' => 'div' ) ) ); - // The upper case is irrelevant but illustrates the case-insentivity. + // The upper case is irrelevant but illustrates the case-insensitivity. $processor = WP_HTML_Processor::create_fragment( '' ); $this->assertTrue( $processor->next_tag( array( 'tag_name' => 'rect' ) ) ); } diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php index 911fa8b910b37..b54fc047ab040 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php @@ -49,7 +49,7 @@ public static function data_single_tag_of_supported_elements() { 'BASE', 'BDI', 'BDO', - 'BGSOUND', // Deprectated. + 'BGSOUND', // Deprecated. 'BIG', 'BLINK', // Deprecated. 'BR', diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorComments.php b/tests/phpunit/tests/html-api/wpHtmlProcessorComments.php index 0cc4fdb0938fa..4ea17f2318b51 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorComments.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorComments.php @@ -41,8 +41,8 @@ public static function data_comments() { 'Invalid HTML comment !' => array( '', WP_HTML_Processor::COMMENT_AS_INVALID_HTML, ' Bang opener ' ), 'Invalid HTML comment ?' => array( '', WP_HTML_Processor::COMMENT_AS_INVALID_HTML, ' Question opener ' ), 'CDATA comment' => array( ' cdata body ', WP_HTML_Processor::COMMENT_AS_CDATA_LOOKALIKE, ' cdata body ' ), - 'Processing instriction comment' => array( '', WP_HTML_Processor::COMMENT_AS_PI_NODE_LOOKALIKE, ' Instruction body. ', 'pi-target' ), - 'Processing instriction php' => array( '', WP_HTML_Processor::COMMENT_AS_PI_NODE_LOOKALIKE, ' const HTML_COMMENT = true; ', 'php' ), + 'Processing instruction comment' => array( '', WP_HTML_Processor::COMMENT_AS_PI_NODE_LOOKALIKE, ' Instruction body. ', 'pi-target' ), + 'Processing instruction php' => array( '', WP_HTML_Processor::COMMENT_AS_PI_NODE_LOOKALIKE, ' const HTML_COMMENT = true; ', 'php' ), ); } diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php index a03a9ab806a93..b5d86be06effb 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php @@ -132,8 +132,8 @@ public function data_external_html5lib_tests() { /** * Determines whether a test case should be skipped. * - * @param string $test_name Test name. - * @param string $expected_tree Expected HTML tree structure. + * @param string|null $test_context_element Context element for fragment parsing, or null for full document parsing. + * @param string $test_name Test name. * * @return bool True if the test case should be skipped. False otherwise. */ @@ -338,12 +338,13 @@ static function ( $a, $b ) { } /** - * Convert a given Html5lib test file into a test triplet. + * Convert a given Html5lib test file into a series of test cases. * * @param string $filename Path to `.dat` file with test cases. * - * @return array|Generator Test triplets of HTML fragment context element, - * HTML, and the DOM structure it represents. + * @return Generator Test cases as 4-element arrays of line number, + * HTML fragment context element, HTML, and the + * DOM structure it represents. */ public static function parse_html5_dat_testfile( $filename ) { $handle = fopen( $filename, 'r', false ); diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php index ffc99ad58fd8e..da6d959eb75e0 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php @@ -163,7 +163,7 @@ public function test_in_body_button_with_no_button_in_scope() { } /** - * Verifies what when inserting a BUTTON element, when a BUTTON is already in scope, + * Verifies that when inserting a BUTTON element, when a BUTTON is already in scope, * that the open button is closed with all other elements inside of it. * * @ticket 58961 @@ -195,7 +195,7 @@ public function test_in_body_button_with_button_in_scope_as_parent() { } /** - * Verifies what when inserting a BUTTON element, when a BUTTON is already in scope, + * Verifies that when inserting a BUTTON element, when a BUTTON is already in scope, * that the open button is closed with all other elements inside of it, even if the * BUTTON in scope is not a direct parent of the new BUTTON element. * diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesListElements.php b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesListElements.php index 0c7e3422f09fc..e89896da2298e 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesListElements.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesListElements.php @@ -94,7 +94,7 @@ public function test_in_body_li_generates_implied_end_tags_inside_open_li_but_st $this->assertSame( array( 'HTML', 'BODY', 'LI', 'BLOCKQUOTE', 'LI' ), $processor->get_breadcrumbs(), - 'LI should have left the BLOCKQOUTE open, but closed it.' + 'LI should have left the BLOCKQUOTE open, but closed it.' ); } @@ -234,7 +234,7 @@ public function test_in_body_dd_generates_implied_end_tags_inside_open_dd_but_st $this->assertSame( array( 'HTML', 'BODY', 'DD', 'BLOCKQUOTE', 'DD' ), $processor->get_breadcrumbs(), - 'DD should have left the BLOCKQOUTE open, but closed it.' + 'DD should have left the BLOCKQUOTE open, but closed it.' ); } @@ -370,7 +370,7 @@ public function test_in_body_dt_generates_implied_end_tags_inside_open_dt_but_st $this->assertSame( array( 'HTML', 'BODY', 'DT', 'BLOCKQUOTE', 'DT' ), $processor->get_breadcrumbs(), - 'DT should have left the BLOCKQOUTE open, but closed it.' + 'DT should have left the BLOCKQUOTE open, but closed it.' ); } diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php index 0e72f9d726835..beb4cc60f6d95 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php @@ -518,7 +518,7 @@ public function test_can_seek_after_document_ends( $html_with_target_element ) { */ public static function data_incomplete_html_with_target_nodes_for_seeking() { return array( - 'Compete document' => array( '
' ), + 'Complete document' => array( '
' ), 'Incomplete document' => array( '
' ); * $processor->next_tag(); * $processor->set_attribute('class', '" onclick="alert'); - * echo $p; + * echo $processor->get_updated_html(); * //
* ``` * - * To prevent it, `set_attribute` calls `esc_attr()` on its given values. + * To prevent it, `set_attribute` escapes dangerous characters (`"`, `'`, `<`, `>`, `&`) using HTML character references. * * ```php *
@@ -1523,11 +1523,11 @@ public function test_calling_remove_class_with_all_listed_class_names_removes_th $this->assertSame( '
Text
', $processor->get_updated_html(), - 'Updated HTML does not reflect class attribute removed via subesequent remove_class() calls' + 'Updated HTML does not reflect class attribute removed via subsequent remove_class() calls' ); $this->assertNull( $processor->get_attribute( 'class' ), - "get_attribute( 'class' ) did not return null for class attribute removed via subesequent remove_class() calls" + "get_attribute( 'class' ) did not return null for class attribute removed via subsequent remove_class() calls" ); } diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index f43d1fffaad0e..4a09403b7b23e 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -415,7 +415,7 @@ public function test_updates_basic_modifiable_text_on_supported_nodes( string $h $this->assertSame( $transformed, $processor->get_updated_html(), - "Should have transformed the HTML as expected why modifying the target node's modifiable text." + "Should have transformed the HTML as expected when modifying the target node's modifiable text." ); }