WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 3 months ago

#11678 new defect (bug)

wpautop() fails on uppercase closing tags

Reported by: joehoyle Owned by:
Milestone: Future Release Priority: normal
Severity: minor Version: 2.9
Component: Formatting Keywords: gsoc has-patch dev-feedback wpautop
Focuses: Cc:

Description

To reproduce, in a post enter:

<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</P>

View the post (source) and you get:

<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</P></p>

Because I (incorrectly) entered an uppercase closing </P> tag, wpautop() thinks there is no closing tag so adds a </p>, which then often renders as a double <p> tag. Close if this is not a bug, though I thought it may be good to do some sanitizing or something on uppercase tags.

Attachments (2)

11678.case-insensitive-regex.patch (3.9 KB) - added by kurtpayne 3 years ago.
Changing regexes to use case-insensitive modifier
11678.lowercase-tagnames.patch (531 bytes) - added by kurtpayne 3 years ago.
Change text to use lowercase tagnames

Download all attachments as: .zip

Change History (10)

comment:1 joehoyle4 years ago

I noticed if you switch between HTML and Visual in the editor it changes it to lowercase, however I ran into this problem when I imported several thousand posts, so the editor was not used

comment:2 follow-ups: azaozz4 years ago

  • Keywords reporter-feedback added; wpautop removed

Upper case tags haven't been in use for 6-7 years I think. They are also invalid with most current doctypes and the visual editor would always convert them to lower case.

In that terms adding support to wpautop() for upper case tags would only introduce unneeded overhead. It seems the best solution for this is to replace all upper case tags while importing or directly in the database after importing. That would make your content futureproof too.

Did you use one of the build-in importers? If this is a common problem we need to fix the importer or perhaps can make a small plugin to do that automatically after import.

comment:3 in reply to: ↑ 2 nacin4 years ago

Replying to azaozz:

Upper case tags haven't been in use for 6-7 years I think. They are also invalid with most current doctypes

Sadly, in (non-X)HTML 5, tag names are case insensitive and uppercase is valid.

comment:4 in reply to: ↑ 2 joehoyle4 years ago

Did you use one of the build-in importers? If this is a common problem we need to fix the importer or perhaps can make a small plugin to do that automatically after import.

No, it was a custom import from a bespoke old CMS, I have changed it to convert tags to lowercase, I just created the issue incase any other the devs thought it was something worth fixing. Feel free to close as invalid, though I think nacin does raise a good point, that in HTML 4 Uppercase tags are valid.

comment:5 nacin4 years ago

  • Keywords reporter-feedback removed
  • Milestone changed from Unassigned to Future Release

comment:6 wojtek.szkutnik4 years ago

  • Keywords gsoc added

kurtpayne3 years ago

Changing regexes to use case-insensitive modifier

kurtpayne3 years ago

Change text to use lowercase tagnames

comment:7 kurtpayne3 years ago

  • Cc kpayne@… added
  • Keywords has-patch dev-feedback added

Looks like there's two ways to handle it.

1.) Fix the text to have lowercase tag names before performing the transformations. This makes the most sense to me since the text is being changed anyway and the patch is minimally invasive.

2.) Change the regular expressions to be case insensitive. The performance overhead should be negligible. My latest profiles show that wpautop() is being called ~11 times. This patch added ~0.6ms compared to a previous profile. This patch is more invasive, but the output may more closely resemble the original text.

I've submitted a patch for each approach. Let me know what you think.

comment:8 nacin3 months ago

  • Component changed from Template to Formatting
  • Keywords wpautop added
Note: See TracTickets for help on using tickets.