#33645 closed defect (bug) (fixed)
wpautop breaks HTML comments
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.3.1 | Priority: | normal |
Severity: | normal | Version: | 4.2.4 |
Component: | Formatting | Keywords: | has-patch wpautop fixed-major |
Focuses: | Cc: |
Description
Our site had a commented out section of code (within <!-- -->) within a post on a page.
previously ( < 4.2.3), newlines in the code were replaced with a space. Now this gets replaced with <!-- wpnl -->, which closes the user made commented out code prematurely, leading to elements that should not be displayed being displayed on the live site.
code in question:
Was (< 4.2.3):
// Strip newlines from all elements. $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) );
Now (4.2.4):
// Find newlines in all elements and add placeholders. $pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) );
Attachments (5)
Change History (25)
#1
@
10 years ago
- Summary changed from Change in formatting.php [ Version Wordpress 4.2.4] to add wpnl comment breaks sites. to Change in wp-includes/class-wp-embed.php ? [ Version Wordpress 4.2.4] to add wpnl comment breaks sites
#3
@
10 years ago
- Summary changed from Change in wp-includes/class-wp-embed.php ? [ Version Wordpress 4.2.4] to add wpnl comment breaks sites to wpautop breaks HTML comments
#4
@
10 years ago
- Keywords needs-patch needs-unit-tests needs-testing added
- Milestone changed from Awaiting Review to 4.2.5
Thanks for the report, Thomas!
#5
@
10 years ago
I wrote a new patch for this but it's still not working. The block element regex is also doing weird things to PARAM elements. :(
#6
@
10 years ago
- Keywords has-patch added; needs-patch needs-unit-tests needs-testing removed
- Owner set to miqrogroove
- Status changed from new to accepted
Fixed and tested both bugs in attachment.
#9
@
10 years ago
Explanation of optimizations in the second patch:
In this particular regexp, we are not actually looking for the end of an element, but the end of an element's name. It is therefore not always necessary to find a >
character because the name can also be delimited by whitespace. For improved speed and readability, I have reduced this term to simply [\s>]
The same tests still pass.
#11
@
10 years ago
- Keywords commit removed
- Owner changed from miqrogroove to azaozz
- Status changed from accepted to assigned
Ozz will approve when ready
#12
follow-up:
↓ 20
@
10 years ago
This is caused by not replacing the line break placeholders <!-- wpnl -->
at the end of wpautop(). So the first line of the patch is not needed in order to fix it.
I'm also a bit unsure about '!(<' . $allblocks . '[\s>])!'
in a dot release. Before we used to match the whole tag, now we match just the beginning. That looks fine but might introduce other edge cases and we don't have adequate tests for it. Also, it has to be '!(<' . $allblocks . '[\s/>])!'
to match things like <hr/>
.
How about we add 33645.2.patch without the first line to 4.3.1, and add the revised patch to 4.4?
Also, ideally we should exclude HTML comments from wpautop completely, same as the content of CDATA, <script>, and <style> tags, perhaps similarly to how <pre> tags are handled.
#14
@
10 years ago
- Keywords wpautop added
In 33645-4.4-expanded.patch one of the tests will fail if wpautop doesn't insert whitespace between self-closing blocks.
#16
@
10 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopen for 4.3.1 consideration. The preferred patch for there is 33645-4.3.1.patch
#18
@
10 years ago
- Keywords needs-unit-tests added
- Resolution fixed deleted
- Status changed from closed to reopened
Needs unit tests
#19
@
10 years ago
- Keywords needs-unit-tests removed
- Resolution set to fixed
- Status changed from reopened to closed
#20
in reply to:
↑ 12
@
9 years ago
Replying to azaozz:
Also, ideally we should exclude HTML comments from wpautop completely, same as the content of CDATA, <script>, and <style> tags, perhaps similarly to how <pre> tags are handled.
Do I read this correctly: this part was never handled, leading to #33834?
Here's a dead simple test case to use:
-
tests/phpunit/tests/formatting/Autop.php
524 524 $this->assertEquals( $expected, trim( wpautop( $content ) ) ); 525 525 } 526 526 527 /** 528 * wpautop() should skip HTML comments 529 * 530 * @ticket 33645 531 */ 532 function test_that_wpautop_skips_html_comments() { 533 $content = ' 534 <!-- .column .something --> 535 '; 536 537 $expected = ' 538 <!-- .column .something --> 539 '; 540 541 $this->assertEquals( $expected, trim( wpautop( $content ) ) ); 542 } 543 527 544 }
For information: Affected post on site (for reference)
code in post:
code produced on page by Wordpress: