Make WordPress Core

Opened 10 years ago

Last modified 10 months ago

#38656 new defect (bug)

wpautop incorrectly handling paragraphs within block elements

Reported by: pento Owned by:
Priority: normal Milestone: Future Release
Component: Formatting Version: 5.0
Severity: normal Keywords: has-patch has-unit-tests has-screenshots has-test-info
Cc: Focuses:

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)

38656.diff​ (3.8 KB ) - added by pento 10 years ago.
38656.2.diff​ (5.6 KB ) - added by pento 10 years ago.
38656.3.diff​ (6.8 KB ) - added by pento 10 years ago.
38656.4.diff​ (7.1 KB ) - added by desrosj 8 years ago.

Download all attachments as: .zip

Change History (12)

#1 @pento
10 years ago

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

#2 @pento
10 years ago

38656.2.diff​ makes this all work with nested peeable and unpeeable elements, and adds more unit tests.

#3 @pento
10 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 @desrosj
8 years ago

  • Keywords needs-refresh added
  • Version → 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 @ozgursar
10 months 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.


10 months 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.

https://core.trac.wordpress.org/ticket/38656

#7 @vladimiraus
10 months ago

Applied patch 4 with some tests changes.

#8 @ozgursar
10 months 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

  1. 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');

  1. Create a post
  2. Add the shortcode [wpautop_test]
  3. View the generated source code on the frontend
  4. Apply the patch
  5. View the generated source code on the frontend again to see the changes
  6. ✅ Patch is solving the problem

Expected result

  • We are expecting to see the p tags properly added to the shortcode content.

Screenshots/Screencast with results

Before:
https://i.imgur.com/XddSQBj.png

After:
https://i.imgur.com/m9JIYGe.png

Note: See TracTickets for help on using tickets.