@@ -3107,24 +3107,50 @@ 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
3126+ $ raw_content = <<<'HTML'
3127+ \\&\\ & &invalid; < < &lt;
3128+ HTML;
3129+ $ rendered = <<<'HTML'
3130+ <p>\\&\\ & &invalid; < < &lt;</p>
3131+ HTML;
3132+ $ author_name = <<<'HTML'
3133+ \\&\\ & &invalid; < < &lt;
3134+ HTML;
3135+ $ author_user_agent = <<<'HTML'
3136+ \\&\\ & &invalid; < < &lt;
3137+ HTML;
3138+
31133139 $ this ->assertTrue ( current_user_can ( 'unfiltered_html ' ) );
31143140 $ this ->verify_comment_roundtrip (
31153141 array (
3116- 'content ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3117- 'author_name ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3118- 'author_user_agent ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3142+ 'content ' => $ raw_content ,
3143+ 'author_name ' => $ raw_content ,
3144+ 'author_user_agent ' => $ raw_content ,
31193145 'author ' => self ::$ superadmin_id ,
31203146 ),
31213147 array (
31223148 'content ' => array (
3123- 'raw ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3124- 'rendered ' => ' <p> \\ \& \\ \ & &invalid; < < &lt; ' . "\n </p> " ,
3149+ 'raw ' => $ raw_content ,
3150+ 'rendered ' => $ rendered ,
31253151 ),
3126- 'author_name ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3127- 'author_user_agent ' => '\\ \& \\ \ & &invalid; < < &lt; ' ,
3152+ 'author_name ' => $ author_name ,
3153+ 'author_user_agent ' => $ author_user_agent ,
31283154 'author ' => self ::$ superadmin_id ,
31293155 )
31303156 );
0 commit comments