Make WordPress Core

Opened 7 years ago

Last modified 5 years ago

#38656 new defect (bug)

wpautop incorrectly handling paragraphs within block elements

Reported by: pento's profile pento Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.0
Component: Formatting Keywords: has-patch needs-unit-tests needs-testing needs-refresh
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)

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

Download all attachments as: .zip

Change History (8)

@pento
7 years ago

#1 @pento
7 years ago

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

@pento
7 years ago

#2 @pento
7 years ago

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

@pento
7 years ago

#3 @pento
7 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.

@desrosj
5 years ago

#4 @desrosj
5 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.

Note: See TracTickets for help on using tickets.