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

WordPress Trac noreply at wordpress.org
Sun Apr 21 16:49:57 UTC 2024


#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           |
-------------------------------------------------+-------------------------

Comment (by robertthenoob):

 Replying to [comment:39 azaozz]:
 > 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 (untested):
 > {{{
 > - $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 cases as-is.
 If a fix is desirable, better to add in a plugin so the users can enable
 or disable it at will.
 Thanks for it.

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


More information about the wp-trac mailing list