Make WordPress Core

Opened 4 years ago

Last modified 3 weeks ago

#33466 reopened defect (bug)

wpautop breaks multi-line textarea content

Reported by: takayukister Owned by: miqrogroove
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Formatting Keywords: wpautop, bulk-reopened
Focuses: Cc:

Description (last modified by miqrogroove)

Applying wpautop() breaks multi-line content of textarea element because it replaces each newline with <br />. A textarea can't have HTML in its content.

You can reproduce the problem with the following code:

$text = '<textarea name="test">
Lorem ipsum dolor sit amet,
consectetur adipisicing elit,
sed do eiusmod tempor
incididunt ut labore
et dolore magna aliqua.</textarea>';

echo wpautop( $text );

Attachments (4)

wpautop.diff (653 bytes) - added by takayukister 4 years ago.
patch for wpautop
33466.2.patch (670 bytes) - added by chriscct7 4 years ago.
Applies from proper directory
33466-tests.diff (1.3 KB) - added by miqrogroove 4 years ago.
33466.diff (2.0 KB) - added by wonderboymusic 4 years ago.

Download all attachments as: .zip

Change History (18)

4 years ago

patch for wpautop

#1 @chriscct7
4 years ago

  • Keywords needs-patch dev-feedback added
  • Version changed from trunk to 4.3

I strongly suspect this is related to #33377.

#2 @chriscct7
4 years ago

  • Keywords needs-refresh added; needs-patch removed

Patch needs refresh to apply from correct directory, not a new patch. Working on it now.

4 years ago

Applies from proper directory

#3 @chriscct7
4 years ago

  • Keywords has-patch added; needs-refresh removed
  • Milestone changed from Awaiting Review to 4.4
  • Owner set to chriscct7
  • Status changed from new to assigned

New patch from proper directory. Ready for merge post @azaozz or @miqrogroove review. Could be a 4.3.1 candidate.

#4 @miqrogroove
4 years ago

  • Keywords wpautop added

#5 @miqrogroove
4 years ago

  • Keywords needs-unit-tests added

I think we need to take a very thoughtful look at why we are treating PRE differently from SCRIPT and STYLE. Until we have that sorted out, I'm not confident we have the best patch here. Anyone have thoughts on that already?

#6 @miqrogroove
4 years ago

  • Description modified (diff)
  • Keywords dev-feedback has-patch needs-unit-tests removed
  • Version 4.3 deleted

4.3 and 4.2 both failed the attached tests. I am correcting the ticket, including the description to reflect the fact that a newline is required after any textarea element. Omitting the newline causes browsers to strip leading whitespace.

#7 @azaozz
4 years ago

The four tags that need "special treatment" are pre, scritp, style and textarea. We want to preserve line breaks/white space in them and prevent any extra tags like <br>. This needs to happen in both wpautop -- JS and PHP.

In addition:

  • For <pre> we need to keep consecutive white spaces.
  • For <textarea> we may have to make sure </textarea> is escaped to &lt;/textarea> (needs testing).

The above patches are a good start but thinking we can handle these four tags in the same way as suggested in comment 5. This needs to be in both JS and PHP.

Last edited 4 years ago by azaozz (previous) (diff)

#8 @miqrogroove
4 years ago

Based on the earlier test results, I'd say PRE is being handled correctly, whereas none of the others seem to work, including the patches above.

4 years ago

#9 @wonderboymusic
4 years ago

  • Keywords has-patch added

33466.diff combines patches - unit tests fail

#10 @miqrogroove
4 years ago

  • Keywords has-patch removed

#11 @wonderboymusic
4 years ago

  • Owner changed from chriscct7 to miqrogroove

#12 @miqrogroove
4 years ago

  • Milestone changed from 4.4 to Future Release

As long as it has my name on it, let's get real about the Milestone :) This is a maybe 4.5 ticket for now.

#13 @iseulde
3 months ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from assigned to closed

This ticket has not seen any activity in over *two* years, so I'm closing it as "wontfix".

The ticket may lack decisiveness, may have become irrelevant, or may not have gathered enough interest.

If you think this ticket does deserve some attention again, feel free to reopen.

For bugs, it would be great if you could provide updated steps to reproduce against the latest version of WordPress (5.0.2 at the time of writing). Remember images or a video can be superior to explain a problem. At the very least, quickly test again to make sure the bug still exists.

If it’s an enhancement or feature, some extra motivation may help.

Thank you for your contributions to WordPress! <3

#14 @JeffPaul
3 weeks ago

  • Keywords bulk-reopened added
  • Milestone set to Awaiting Review
  • Resolution wontfix deleted
  • Status changed from closed to reopened

A decision was made to reopen tickets that were closed in the bulk edit that this ticket was affected by. This ticket is being placed back into the Awaiting Review milestone so it can be individually evaluated and verified to determine if it is still relevant/valid or reproducible.

Note: See TracTickets for help on using tickets.