[wp-trac] [WordPress Trac] #2691: HTML comments in posts aren't handled properly.

WordPress Trac noreply at wordpress.org
Thu Jan 26 21:35:53 UTC 2023


#2691: HTML comments in posts aren't handled properly.
-------------------------------------------------+-------------------------
 Reporter:  gord                                 |       Owner:
                                                 |  adamsilverstein
     Type:  defect (bug)                         |      Status:  accepted
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Formatting                           |     Version:  2.8.5
 Severity:  normal                               |  Resolution:
 Keywords:  wpautop dev-feedback has-patch       |     Focuses:
  needs-unit-tests needs-refresh close           |
-------------------------------------------------+-------------------------
Changes (by azaozz):

 * keywords:  wpautop dev-feedback has-patch needs-unit-tests needs-refresh
     => wpautop dev-feedback has-patch needs-unit-tests needs-refresh close


Comment:

 Frankly I'd be quite reluctant to patch autop at this stage. It is "on its
 way out" and chances to introduce new bugs there are pretty high.

 Looking at the patch, this seems problematic:
 {{{
 if ( strpos( $pee, '<!--' ) !== false ) {
     $pee = preg_replace( '|<p>\s*<\!--|', '<!--', $pee );
 }}}

 It will remove `<p>` from strings that start with a comment like `<p><!--
 123 -->text goes here</p>`.

 If this **must be** patched, a preferable way would be to avoid wrapping
 lines that contain only HTML comments. I.e. something like:
 {{{
 - $pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
 + $part = trim( $tinkle, "\n" );

 if (
     strpos( $part, '<!--' ) === 0 &&
     strpos( $part, '-->' ) === ( strlen( part ) - 3 )
 ) {
     $pee .= "$part\n"; // Don't wrap stand-alone HTML comments in <p>.
 } else {
     $pee .= "<p>$part</p>\n";
 }}}

 Support for multi-line HTML comments would have to be added similarly to
 how `<pre>` tags are treated, i.e. completely excluded from autop.

 Still, the chance to introduce regressions here even by fixing the
 behavior are high. Perhaps better to leave this and similar fixes as-is.
 If a fix is desirable, better to add in a plugin so the users can enable
 or disable it at will.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/2691#comment:39>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list