Skip to content

Commit 36ebba8

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 7bec60e commit 36ebba8

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,21 +3110,34 @@ public function test_comment_roundtrip_as_editor_unfiltered_html() {
31103110
public function test_comment_roundtrip_as_superadmin() {
31113111
wp_set_current_user( self::$superadmin_id );
31123112

3113+
$raw_content = <<<'HTML'
3114+
\\&\\ &amp; &invalid; < &lt; &amp;lt;
3115+
HTML;
3116+
$rendered = <<<'HTML'
3117+
<p>\\&#038;\\ &amp; &invalid; < &lt; &amp;lt;</p>
3118+
HTML;
3119+
$author_name = <<<'HTML'
3120+
\\&amp;\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;
3121+
HTML;
3122+
$author_user_agent = <<<'HTML'
3123+
\\&\\ &amp; &invalid; &lt; &lt; &amp;lt;
3124+
HTML;
3125+
31133126
$this->assertTrue( current_user_can( 'unfiltered_html' ) );
31143127
$this->verify_comment_roundtrip(
31153128
array(
3116-
'content' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
3117-
'author_name' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
3118-
'author_user_agent' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
3129+
'content' => $raw_content,
3130+
'author_name' => $raw_content,
3131+
'author_user_agent' => $raw_content,
31193132
'author' => self::$superadmin_id,
31203133
),
31213134
array(
31223135
'content' => array(
3123-
'raw' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
3124-
'rendered' => '<p>\\\&#038;\\\ &amp; &invalid; < &lt; &amp;lt;' . "\n</p>",
3136+
'raw' => $raw_content,
3137+
'rendered' => $rendered,
31253138
),
3126-
'author_name' => '\\\&amp;\\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;',
3127-
'author_user_agent' => '\\\&\\\ &amp; &invalid; &lt; &lt; &amp;lt;',
3139+
'author_name' => $author_name,
3140+
'author_user_agent' => $author_user_agent,
31283141
'author' => self::$superadmin_id,
31293142
)
31303143
);

0 commit comments

Comments
 (0)