Opened 7 years ago
Last modified 2 years ago
#2691 reopened defect (bug)
HTML comments in posts aren't handled properly.
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | General | Version: | 2.8.5 |
| Severity: | normal | Keywords: | wpautop needs-patch |
| Cc: | vikingjs, mrclay |
Description
When an HTML comment is added in a post, autop adds paragraph ( <p> ) tags around the comment and for multi-line comments line breaks ( <br /> ) are added after every line. This should not happen in HTML comments.
This ticket is similar to #712 which was closed with wontfix. I would like to know why this isn't seen as an issue? It prevents the addition of RDF and other metadata, not to mention just plain old HTML comments in posts.
Change History (7)
Maybe a bandaid on it? (e.g.)
$pee = preg_replace('!<p><!--(.*?)--></p>!ise', " '<!--' . stripslashes(clean_pre('$1')) . '-->' ", $pee);
clean_pre() will ruin any comments which are supposed to have <p> and <br /> in them, but that's an even edgier case.
Gord, you could also try a plugin replacement for wpautop -- I know Markdown handles comments fine.
- Resolution set to wontfix
- Status changed from new to closed
No traction in over a year, so closing as wontfix.
Feel free to reopen if you have patches/suggestions/...
- Cc vikingjs added
- Resolution wontfix deleted
- Status changed from closed to reopened
- Version changed from 2.0 to 2.8.5
I can't believe this got no traction - I use plugins that conscientiously mark where their added content begins and ends using HTML comments, and those comments are adding empty paragraphs in my posts, which in some cases affect layout and undermine the aesthetics of the page.
This issue affects anyone who uses plugins that modify the text of the blog post, e.g., SexyBookmarks.
I'll look at what it would take to patch it, but someone who knows how and where the unwanted behavior is occurring could do it in a fraction of the time.
- Keywords wpautop needs-patch added; autop removed
- Milestone set to Future Release
The function responsible is called wpautop() and can be found in /wp-includes/formatting.php
Replying to scribu:
The function responsible is called wpautop() and can be found in /wp-includes/formatting.php
I took a look and I'm probably not the guy to be fixing this. As far as I can tell the band-aid advised by random above is a good fix. The reason I think I'm not the guy is because I don't know why stripslashes() and clean_pre() are needed for a comment, so I bow to the superior understanding of others.
random calls his patch a band-aid, but it would be just another in a long list of band-aids in the function. The philosophy seems to be to add paragraph tags and then go back and repair special cases where they broke things. This would be just another special case. Ideally it would be better simply not to apply the wpautop routines to comments (or some of the other cases like embed tags) in the first place.
- Cc mrclay added
I've created a more resilient autop implementation and a more rigorous testcase cobbled from various WP tickets. It avoids the dangerous regex operations by doing most work in a DOMDocument object.
This is undoubtedly slower than current wpautop (and may choke on extremely invalid HTML), but happily handles markup that the current wpautop breaks. Since there's no real spec for wpautop, it's hard to duplicate the style of markup wpautop outputs when it does work, but a lot of testing will surely be necessary.

This is what is implied: nobody who has seen this has found it important enough to spend their time rewriting autop to work around comments. The applicable mantra is "edge case." You are welcome to work up a patch and submit it for testing and consideration.