Make WordPress Core

Opened 18 years ago

Closed 16 years ago

Last modified 14 years ago

#2813 closed defect (bug) (wontfix)

wpautop() adding erroneous <br/> tags

Reported by: pidge's profile pidge Owned by: pishmishy's profile pishmishy
Milestone: Priority: normal
Severity: normal Version: 2.0.3
Component: Template Keywords: <br> has-patch needs-testing
Focuses: Cc:


A few things happens when posting a well formed valid xhtml content via xml-rpc.

  1. <br/> tags are converted to <br>
  1. When publishing WP appends extra <br/> (actually <br>) tags even if the post is a well formed validated xhtml content.

To reproduce, compose a simple entry with a <br/> using a client editor (in our case, we used our application - Zoundry). The xhtml content looks like:

<br />

Debug logs shows that the xml-rpc description field is as expected:


Next, go into the WP MySQL database and look at the posted content:
In, WP 2.0, noticed that the <br/> is converted to <br>. E.g.:


I found that this is due to a bug in kses.php. It seems this part (<br/> converted to <br>) is resolved in WP 2.0.1. That is, the database content is:


When the above content is published via WP, the html in the published entry inserts two extra <br> tags and also note that the <br/> is converted to a non-valid <br> tag (possibly a bug in wpautop):


This applies to WP 2.0 and 2.01 (verified) and users have reported same issue in WP 2.02.

Attachments (1)

2813.patch (716 bytes) - added by pishmishy 16 years ago.
Replaces match 0 or more with match 1 or more in regex

Download all attachments as: .zip

Change History (16)

#1 @pidge
18 years ago

Update - another user reported the same issue (extra <br/> tags) in v 2.0.3.

#2 @pidge
18 years ago

Another update - it seems, in 2.03, the <br/> tags are well-formed, though the extra <br/> tags are still inserted.

#3 @foolswisdom
18 years ago

  • Milestone changed from 2.0.3 to 2.1
  • Summary changed from <br /> tags are not handled correctly when posted via xml-rpc to Extra <br /> tags added when posted via xml-rpc
  • Version changed from 2.0.2 to 2.0.3

#4 @matt
17 years ago

  • Milestone changed from 2.1 to 2.2

#5 @foolswisdom
17 years ago

  • Milestone changed from 2.2 to 2.3

#6 @josephscott
17 years ago

I've confirmed that the double <br /> problem still exists in -trunk, but it doesn't have anything to do with XML-RPC. If you turn off the visual editor and paste the example into a blog post:

<br />

You get the same double <br />.

#7 @ryan
17 years ago

  • Milestone changed from 2.3 to 2.4

#8 @jcheng
17 years ago

Please, if you're going to change this behavior, give us a way to know whether the line break conversion will be applied or not! We put a lot of work into Windows Live Writer to work correctly with WP's current behavior, for both posting and fetching existing posts.

As an example of what not to do, Movable Type has a per-post setting for whether line breaks should be converted to p and br tags, but there's no way for an XML-RPC client to reliably know what the setting is for an existing post.

#9 @pishmishy
16 years ago

  • Component changed from XML-RPC to General
  • Keywords xml-rpc removed
  • Owner changed from anonymous to pishmishy
  • Status changed from new to assigned
  • Summary changed from Extra <br /> tags added when posted via xml-rpc to wpautop() adding eroniuous <br/> tags

Problem is located in lines 81-85 of formatting.php (at least it disappears when you comment these lines out)

if ($br) {
               $pee = preg_replace('/<(script|style).*?<\/\\1>/se', 'str_replace("\n", "<WPPreserveNewline />", "\\0")', $pee);
               $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
               $pee = str_replace('<WPPreserveNewline />', "\n", $pee);

#10 @santosj
16 years ago

  • Summary changed from wpautop() adding eroniuous <br/> tags to wpautop() adding erroneous <br/> tags

16 years ago

Replaces match 0 or more with match 1 or more in regex

#11 @pishmishy
16 years ago

  • Keywords has-patch needs-testing added

My regex-foo isn't strong but I think that the problem was a * where a + was intended. Pretty sure the bug is somewhere in that regular expression although I'm not entirely sure if I've fixed it or just broken the intended functionality =)

#12 @santosj
16 years ago

  • Component changed from General to XML-RPC

#13 @santosj
16 years ago

  • Component changed from XML-RPC to Template

#14 @pishmishy
16 years ago

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

Closing this was WONTFIX. Doesn't appear to be much call for this fix.

#15 @hakre
14 years ago

Related: #1706 (?)

Note: See TracTickets for help on using tickets.