Make WordPress Core

Opened 10 months ago

Last modified 4 weeks ago

#63148 new defect (bug)

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

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

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
10 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 10 months ago by SirLouen (previous) (diff)

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


10 months ago
#2

  • Keywords has-patch added; needs-patch removed

#3 @wordpressdotorg
9 months ago

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

#4 @wildworks
8 weeks ago

  • Keywords needs-unit-tests added
  • Version trunk deleted

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
8 weeks ago

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

#6 @gillesdoge
4 weeks ago

Is this another duplicate of #27350 ?

Note: See TracTickets for help on using tickets.