Opened 9 years ago
Last modified 6 weeks ago
#38656 new defect (bug)
wpautop incorrectly handling paragraphs within block elements
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | 5.0 |
| Component: | Formatting | Keywords: | has-patch has-unit-tests has-screenshots has-test-info |
| Focuses: | Cc: |
Description
When there are two line breaks within a block element, wpautop() will replace it with </p><p>, but the corresponding opening and closing tags won't exist.
For example, <div>a\n\nb</div> will produce <div>a</p><p>b</div>, when it really should produce <div>\n<p>a</p>\n<p>b</p>\n</div>.
Attachments (4)
Change History (12)
#2
@
9 years ago
38656.2.diff makes this all work with nested peeable and unpeeable elements, and adds more unit tests.
#3
@
9 years ago
38656.3.diff adds code comments, and some more complex tests.
There's probably value in adding some intelligence to the closing HTML tag detection, so we can handle some basic invalid HTML. For example, a browser will automatically correct <div><span>foo</div>, and treat it as <div><span>foo</span></div>, but wpautop() will get $peeable out of sync, causing problems.
#4
@
7 years ago
- Keywords needs-refresh added
- Version set to 5.0
I was able to reproduce this bug on trunk. 38656.4.diff is a refresh to apply cleanly after coding standards changes.
Running the unit tests using --group 38656 passes, but there is a failure elsewhere in test_that_wpautop_doses_not_add_extra_closing_p_in_figure() when running --group formatting.
When testing in the editor, I see the This block contains unexpected or invalid content message when switching back to visual editor after entering the test markup in the description.
#5
@
6 weeks ago
- Keywords needs-testing removed
Patch Testing Report
Patch Tested 1: https://core.trac.wordpress.org/attachment/ticket/38656/38656.4.diff
Patch Tested 2: https://core.trac.wordpress.org/attachment/ticket/38656/38656.3.diff
❌ Both of the latest patches are failing to apply. So, ticket needs-refresh
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Opera
- OS: macOS
- Theme: Twenty Twenty-One 2.7
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.1
This ticket was mentioned in PR #10817 on WordPress/wordpress-develop by @vladimiraus.
6 weeks ago
#6
- Keywords has-unit-tests added; needs-unit-tests needs-refresh removed
wpautop() incorrectly handling paragraphs within block elements.
Applied patch 4 with trunk corrections plus changes to tests.
#8
@
6 weeks ago
- Keywords has-screenshots has-test-info added
Thanks for fixing the patch @vladimiraus
I was able to apply the PR and verify that the patch works as expected.
Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/10817
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 144.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
- Code Snippets 3.9.4
- Test Reports 1.2.1
Steps taken
- Add the following sample shortcode via Code Snippets or functions.php
function wpautop_test_shortcode() {
$text = <<<EOT
<div>
This is a paragraph.
This is another paragraph.
</div>
EOT;
return wpautop($text);
}
add_shortcode('wpautop_test', 'wpautop_test_shortcode');
- Create a post
- Add the shortcode [wpautop_test]
- View the generated source code on the frontend
- Apply the patch
- View the generated source code on the frontend again to see the changes
- ✅ Patch is solving the problem
Expected result
- We are expecting to see the p tags properly added to the shortcode content.


38656.diff is a first pass at fixing this, it needs many more unit tests.