WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 6 months ago

#33466 assigned defect (bug)

wpautop breaks multi-line textarea content

Reported by: takayukister Owned by: miqrogroove
Milestone: Priority: normal
Severity: normal Version:
Component: Formatting Keywords: wpautop
Focuses: Cc:
PR Number:

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 (16)

@takayukister
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.

@chriscct7
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.

@wonderboymusic
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.

Note: See TracTickets for help on using tickets.