WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 13 months ago

#40135 new defect (bug)

wpautop adds a extra </p>

Reported by: jim5471 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: Formatting Keywords: has-patch 2nd-opinion
Focuses: Cc:

Description (last modified by SergeyBiryukov)

This is similar to bug reported here #39307

post content

<div><img src="/wp-content/uploads/example.jpg" alt="something" /><div>Something</div></div>

generated markup - note wrong </p> after <img>

<div><img src="/wp-content/uploads/example.jpg" alt="something" /></p>
<div>Something</div>
</div>

Attachments (2)

formatting.php (285.8 KB) - added by ayubi 13 months ago.
formating.diff (291.5 KB) - added by ayubi 13 months ago.
New Regex (preg_replace) -> line 567

Download all attachments as: .zip

Change History (7)

#1 @SergeyBiryukov
2 years ago

  • Component changed from General to Import
  • Description modified (diff)

#3 @ocean90
13 months ago

  • Component changed from Import to Formatting

@ayubi
13 months ago

#4 @ayubi
13 months ago

I am new here :) really didn't know how to show the code that i have written like others!
i wrote this line of code for fixing this bug and also have tested

<?php
$pee = preg_replace('/(img\s)?(^">|<\/p>)/', "", $pee);

/wp-includes/formatting.php

Last edited 13 months ago by ayubi (previous) (diff)

@ayubi
13 months ago

New Regex (preg_replace) -> line 567

#5 @ayubi
13 months ago

  • Keywords has-patch 2nd-opinion added

More information About test:
1- Firstly I entered some inline HTML without any whitespace including <img /> using only text mode on the editor and saved directly!
2- then i checked post source and i found that wpautop has added <p></p> after ending <img /> tag.
3- After some research added a new Regex line at /wp-includes/formatting.php and tested again with same process and Bug has been resolved

Last edited 13 months ago by ayubi (previous) (diff)
Note: See TracTickets for help on using tickets.