Make WordPress Core

Opened 19 months ago

Last modified 10 months ago

#63148 new defect (bug)

wpautop() formatting function generate invalid HTML if the text end with an empty <p> tag

Reported by: gillesdoge Owned by:
Priority: normal Milestone: Awaiting Review
Component: Formatting Version:
Severity: normal Keywords: has-test-info has-patch needs-unit-tests
Cc: Focuses:

Description

It's probably my first ticket (hi there 👋 !).

When preparing a migration of an old WordPress, I was facing the following issue:

<?php

$text = "<p>test</p>
<p></p>";

var_dump(wpautop($text);
// Output: string(16) "<p>test</p></p>
// "

You may ask, but why do you need to apply wpautop() on an already formatted text?
Because some of the content needed it (paragraphs only separated by newlines) and some was already formatted with HTML and Classic Editor.

My current countermeasure is to test if the content already have <p> and don't apply wpautop().

Is this a know issue (I found nothing when searching) ?

Change History (6)

#1 @SirLouen
19 months ago

  • Keywords needs-patch has-testing-info added

Welcome @gillesdoge to Trac

Reproduction Report

Description

This report validates that the issue can be reproduced.

Environment

  • WordPress: 6.8-beta3-60042-src
  • PHP: 8.2.28
  • Server: nginx/1.27.4
  • Database: mysqli (Server: 8.4.4 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 134.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Nineteen 3.0
  • MU Plugins: None activated
  • Plugins:
    • Hello Dolly 1.7.2
    • Test Reports 1.2.0

Actual Results

  1. ✅ Error condition occurs (reproduced).

Supplemental Artifacts

https://i.imgur.com/10qkA6o.png

Last edited 19 months ago by SirLouen (previous) (diff)

This ticket was mentioned in ​PR #8569 on ​WordPress/wordpress-develop by ​@sukhendu2002.


19 months ago
#2

  • Keywords has-patch added; needs-patch removed

#3 @wordpressdotorg
17 months ago

  • Keywords has-test-info added; has-testing-info removed

#4 @wildworks
11 months ago

  • Keywords needs-unit-tests added
  • Version trunk

I'm reviewing this ticket in preparation for a 6.9 dry run.

I'm removing the version field, since at least this issue isn't an issue that occurred in an unreleased development branch.

Additionally, unit tests are needed to move this ticket forward.

#5 @gillesdoge
11 months ago

I will try write some PHPUnit tests to reproduce the issue.

#6 @gillesdoge
10 months ago

Is this another duplicate of #27350 ?

Note: See TracTickets for help on using tickets.