@@ -3150,24 +3150,50 @@ public function test_comment_roundtrip_as_editor_unfiltered_html() {
31503150 }
31513151 }
31523152
3153+ /**
3154+ * Ensures that saving a comment as a super-admin does not corrupt the
3155+ * comment content when presented with common edge cases.
3156+ *
3157+ * Note that this test used to assert the wrong behavior due to a bug
3158+ * in {@see wp_html_split()}. Whereby the unescaped `<` used to be
3159+ * mistakenly identified as the start of an HTML tag or comment, this
3160+ * led to accidental replacement “inside” the mistaken tag. The test
3161+ * has been updated with `wp_html_split()` in accordance with the
3162+ * HTML5 living specification.
3163+ *
3164+ * @ticket {TICKET_NUMBER}
3165+ */
31533166 public function test_comment_roundtrip_as_superadmin () {
31543167 wp_set_current_user ( self ::$ superadmin_id );
31553168
3169+ $ raw_content = <<<'HTML'
3170+ \\&\\ & &invalid; < < &lt;
3171+ HTML;
3172+ $ rendered = <<<'HTML'
3173+ <p>\\&\\ & &invalid; < < &lt;</p>
3174+ HTML;
3175+ $ author_name = <<<'HTML'
3176+ \\&\\ & &invalid; < < &lt;
3177+ HTML;
3178+ $ author_user_agent = <<<'HTML'
3179+ \\&\\ & &invalid; < < &lt;
3180+ HTML;
3181+
31563182 $ this ->assertTrue ( current_user_can ( 'unfiltered_html ' ) );
31573183 $ this ->verify_comment_roundtrip (
31583184 array (
3159- 'content ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3160- 'author_name ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3161- 'author_user_agent ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3185+ 'content ' => $ raw_content ,
3186+ 'author_name ' => $ raw_content ,
3187+ 'author_user_agent ' => $ raw_content ,
31623188 'author ' => self ::$ superadmin_id ,
31633189 ),
31643190 array (
31653191 'content ' => array (
3166- 'raw ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3167- 'rendered ' => ' <p> \\ \& \\ \ & &invalid; < < &lt; ' . "\n </p> " ,
3192+ 'raw ' => $ raw_content ,
3193+ 'rendered ' => $ rendered ,
31683194 ),
3169- 'author_name ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3170- 'author_user_agent ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3195+ 'author_name ' => $ author_name ,
3196+ 'author_user_agent ' => $ author_user_agent ,
31713197 'author ' => self ::$ superadmin_id ,
31723198 )
31733199 );
0 commit comments