Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#33377 closed defect (bug) (fixed)

Wpautop may create extra <br> tags

Reported by: azaozz's profile azaozz Owned by: azaozz's profile azaozz
Milestone: 4.3 Priority: high
Severity: normal Version: 4.3
Component: Formatting Keywords: has-patch commit
Focuses: Cc:

Description

Caused by removing the <br> tag normalization from convert_chars() and by the fact that wpautop() uses negative look behind to check for <br /> followed by a line break.

This is also broken in the JS wpautop.

Attachments (3)

33377.patch (2.4 KB) - added by azaozz 10 years ago.
33377.2.diff (3.3 KB) - added by valendesigns 10 years ago.
33377.3.diff (3.2 KB) - added by valendesigns 10 years ago.
alternative regex pattern

Download all attachments as: .zip

Change History (17)

#1 @obenland
10 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.3

#2 @azaozz
10 years ago

The best way to restore the behaviour is to normalize the <br>. This has to be added to the JS wpautop as now we use it on loading the content in TinyMCE.

@azaozz
10 years ago

#3 @azaozz
10 years ago

  • Keywords has-patch added; needs-patch removed

In 33377.patch:

  • PHP wpautop: replace <br> and <br/> with <br /> before converting line breaks.
  • JS wpautop: remove spaces and line breaks after existing <br> before converting line breaks.

#4 @valendesigns
10 years ago

Works as expected for me. +1

#5 @miqrogroove
10 years ago

Would it be easier to normalize BRs as newlines? If that's done before newline normalization, it might work.

#6 @miqrogroove
10 years ago

493	        // Change multiple <br>s into two line breaks, which will turn into paragraphs.

Needs tests for that.

#7 @valendesigns
10 years ago

A lot of tests fail when you move it before line 493.

#8 @valendesigns
10 years ago

33377.2.diff adds a second test and changes the regex pattern on line 493 to account for oddly formatted break tags when making the conversion to paragraphs.

@valendesigns
10 years ago

alternative regex pattern

#9 @miqrogroove
10 years ago

33377.3.diff looks better.

#10 @azaozz
10 years ago

33377.3.diff looks good for now.

Eventually in PHP we should do something similar to the JS -- remove line breaks after any <br>, replace remaining line breaks with <br>, add line breaks after all <br> to make it prettier.

$pee = preg_replace( '|(<br[^>]*>)\s*\n|i', '$1', $pee );
$pee = preg_replace( '|\s*\n|', '<br />', $pee );
$pee = preg_replace( '|(<br[^>]*>)|i', "$1\n", $pee );

This changes the behaviour so a bit reluctant to do it now, so close to release.

#11 @obenland
10 years ago

  • Owner set to azaozz
  • Status changed from new to reviewing

Needs a second review.

This ticket was mentioned in Slack in #core by obenland. View the logs.


10 years ago

#13 @wonderboymusic
10 years ago

  • Keywords commit added

This looks good to me

#14 @azaozz
10 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 33624:

Fix creating of extra <br /> tags in both PHP and JS variants of wpautop(). Add PHP tests to catch similar problems in the future.
Props valendesigns, azaozz. Fixes #33377.

Note: See TracTickets for help on using tickets.