Skip to content

Commit 0440d83

Browse files
committed
Explain tests that were previously asserting invalid behaviors.
1 parent 8779ab6 commit 0440d83

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

tests/phpunit/tests/formatting/wpAutop.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,15 @@ public function data_element_sanity() {
536536
"Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 ]]> -->",
537537
"<p>Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 ]]> --></p>\n",
538538
),
539+
/*
540+
* CDATA sections do not exist within HTML, so even though it looks
541+
* like this should be escaping the entire “inner comment” span, there’s
542+
* actually an invalid comment starting at `<![CDATA[` and ending at
543+
* the very first `>` character, placing the end of the comment at
544+
* what looks like the end of the “normal comment” — the ` -->`. Everything
545+
* afterward is normal HTML data so the `<br>` is a real `BR` element and
546+
* the `]]>` is normal plaintext, not the CDATA terminator.
547+
*/
539548
array(
540549
"Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 --> a\n9 ]]>",
541550
"<p>Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 --> a<br />\n9 ]]></p>\n",

tests/phpunit/tests/formatting/wpHtmlSplit.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public function data_basic_features() {
3030
'abcd <!-- <html> --> efgh',
3131
array( 'abcd ', '<!-- <html> -->', ' efgh' ),
3232
),
33+
/*
34+
* CDATA sections do not exist within HTML, so even though it looks
35+
* like this should be escaping the entire ` <html> ` span, there’s
36+
* actually an invalid comment starting at `<![CDATA[` and ending at
37+
* the very first `>` character, placing the end of the comment at
38+
* the end of `html>`. The rest is normal plaintext content.
39+
*/
3340
array(
3441
'abcd <![CDATA[ <html> ]]> efgh',
3542
array( 'abcd ', '<![CDATA[ <html>', ' ]]> efgh' ),

tests/phpunit/tests/rest-api/rest-comments-controller.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,6 +3107,19 @@ public function test_comment_roundtrip_as_editor_unfiltered_html() {
31073107
}
31083108
}
31093109

3110+
/**
3111+
* Ensures that saving a comment as a super-admin does not corrupt the
3112+
* comment content when presented with common edge cases.
3113+
*
3114+
* Note that this test used to assert the wrong behavior due to a bug
3115+
* in {@see wp_html_split()}. Whereby the unescaped `<` used to be
3116+
* mistakenly identified as the start of an HTML tag or comment, this
3117+
* led to accidental replacement “inside” the mistaken tag. The test
3118+
* has been updated with `wp_html_split()` in accordance with the
3119+
* HTML5 living specification.
3120+
*
3121+
* @ticket {TICKET_NUMBER}
3122+
*/
31103123
public function test_comment_roundtrip_as_superadmin() {
31113124
wp_set_current_user( self::$superadmin_id );
31123125

0 commit comments

Comments
 (0)