@@ -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+ \\&\\ & &invalid; < < &lt;
3173+ HTML;
3174+ $ rendered = <<<'HTML'
3175+ <p>\\&\\ & &invalid; < < &lt;</p>
3176+ HTML;
3177+ $ author_name = <<<'HTML'
3178+ \\&\\ & &invalid; < < &lt;
3179+ HTML;
3180+ $ author_user_agent = <<<'HTML'
3181+ \\&\\ & &invalid; < < &lt;
3182+ HTML;
3183+
31583184 $ this ->assertTrue ( current_user_can ( 'unfiltered_html ' ) );
31593185 $ this ->verify_comment_roundtrip (
31603186 array (
3161- 'content ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3162- 'author_name ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3163- 'author_user_agent ' => '\\ \& \\ \ & &invalid; < < &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 ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3169- 'rendered ' => ' <p> \\ \& \\ \ & &invalid; < < &lt; ' . "\n </p> " ,
3194+ 'raw ' => $ raw_content ,
3195+ 'rendered ' => $ rendered ,
31703196 ),
3171- 'author_name ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3172- 'author_user_agent ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3197+ 'author_name ' => $ author_name ,
3198+ 'author_user_agent ' => $ author_user_agent ,
31733199 'author ' => self ::$ superadmin_id ,
31743200 )
31753201 );
0 commit comments