Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#31499 closed defect (bug) (fixed)

Trim non-breaking spaces from URLs

Reported by: pento's profile pento Owned by: pento's profile pento
Milestone: 4.2 Priority: normal
Severity: normal Version: 2.3
Component: Canonical Keywords: has-patch
Focuses: Cc:

Description

If a link to a WordPress site has a non-breaking space on the end of it, WordPress will give a 404, instead of showing the page. Refreshing the page (allowing the browser to trim the space) causes the page to load correctly.

Attachments (2)

nbsp.html (107 bytes) - added by pento 10 years ago.
31499.diff (727 bytes) - added by pento 10 years ago.

Download all attachments as: .zip

Change History (7)

@pento
10 years ago

@pento
10 years ago

#1 @pento
10 years ago

  • Component changed from General to Canonical
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.2
  • Version set to 2.3

nbsp.html is a sample test case.

31499.diff trims any non-breaking spaces from the end of the URL, it doesn't trim them if there's a trailing / - the assumption is that they were incorrectly included in a copy/paste, for example, if they're at the very end of the URL. If there's a trailing /, we assume it's intentional.

#2 follow-up: @valendesigns
10 years ago

Wouldn't preg_replace do a search and replace for all non-breaking spaces, not just trim the last one?

#3 in reply to: ↑ 2 @pento
10 years ago

Replying to valendesigns:

Wouldn't preg_replace do a search and replace for all non-breaking spaces, not just trim the last one?

The $ at the end of the regex means it'll only match non-breaking spaces at the end of the string.

#4 @valendesigns
10 years ago

Ah, thanks for the explanation. Cheers!

#5 @pento
10 years ago

  • Owner set to pento
  • Resolution set to fixed
  • Status changed from new to closed

In 31838:

If the URL being visited has non-breaking spaces at the end of it, they were probably inserted by an errant URL copy/paste. Instead of showing a 404 for no obvious reason, let's just trim them.

Fixes #31499

Note: See TracTickets for help on using tickets.