Skip to content

Commit d091ce5

Browse files
committed
Fix broken comments controller test: wp_replace_in_html_tags()
Was detecting a non-escaped `<` as the start of an “element” and then replaced a newline in the text as `<!-- wpnl -->` since it thought it was replacing inside a tag. In the end that translated into a raw `\n` again in the end.
1 parent d6e0585 commit d091ce5

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

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

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,24 +3152,50 @@ public function test_comment_roundtrip_as_editor_unfiltered_html() {
31523152
}
31533153
}
31543154

3155+
/**
3156+
* Ensures that saving a comment as a super-admin does not corrupt the
3157+
* comment content when presented with common edge cases.
3158+
*
3159+
* Note that this test used to assert the wrong behavior due to a bug
3160+
* in {@see wp_html_split()}. Whereby the unescaped `<` used to be
3161+
* mistakenly identified as the start of an HTML tag or comment, this
3162+
* led to accidental replacement “inside” the mistaken tag. The test
3163+
* has been updated with `wp_html_split()` in accordance with the
3164+
* HTML5 living specification.
3165+
*
3166+
* @ticket {TICKET_NUMBER}
3167+
*/
31553168
public function test_comment_roundtrip_as_superadmin() {
31563169
wp_set_current_user( self::$superadmin_id );
31573170

3171+
$raw_content = <<<'HTML'
3172+
\\&\\ &amp; &invalid; < &lt; &amp;lt;
3173+
HTML;
3174+
$rendered = <<<'HTML'
3175+
<p>\\&#038;\\ &amp; &invalid; < &lt; &amp;lt;</p>
3176+
HTML;
3177+
$author_name = <<<'HTML'
3178+
\\&amp;\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;
3179+
HTML;
3180+
$author_user_agent = <<<'HTML'
3181+
\\&\\ &amp; &invalid; &lt; &lt; &amp;lt;
3182+
HTML;
3183+
31583184
$this->assertTrue( current_user_can( 'unfiltered_html' ) );
31593185
$this->verify_comment_roundtrip(
31603186
array(
3161-
'content' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
3162-
'author_name' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
3163-
'author_user_agent' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
3187+
'content' => $raw_content,
3188+
'author_name' => $raw_content,
3189+
'author_user_agent' => $raw_content,
31643190
'author' => self::$superadmin_id,
31653191
),
31663192
array(
31673193
'content' => array(
3168-
'raw' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
3169-
'rendered' => '<p>\\\&#038;\\\ &amp; &invalid; < &lt; &amp;lt;' . "\n</p>",
3194+
'raw' => $raw_content,
3195+
'rendered' => $rendered,
31703196
),
3171-
'author_name' => '\\\&amp;\\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;',
3172-
'author_user_agent' => '\\\&\\\ &amp; &invalid; &lt; &lt; &amp;lt;',
3197+
'author_name' => $author_name,
3198+
'author_user_agent' => $author_user_agent,
31733199
'author' => self::$superadmin_id,
31743200
)
31753201
);

0 commit comments

Comments
 (0)