Make WordPress Core

Opened 12 years ago

Closed 11 years ago

#31499 closed defect (bug) (fixed)

Trim non-breaking spaces from URLs

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

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 12 years ago.
31499.diff (727 bytes ) - added by pento 12 years ago.

Download all attachments as: .zip

Change History (7)

@pento
12 years ago

@pento
12 years ago

#1 @pento
12 years ago

  • Component GeneralCanonical
  • Keywords has-patch added
  • Milestone Awaiting Review4.2
  • Version2.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
11 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
11 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
11 years ago

Ah, thanks for the explanation. Cheers!

#5 @pento
11 years ago

  • Owner set to pento
  • Resolutionfixed
  • Status newclosed

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.