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



git-svn-id: https://develop.svn.wordpress.org/trunk@31838 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2015-03-20 01:01:52 +00:00
parent 71aa4b15f6
commit 182dd8606e
1 changed files with 5 additions and 0 deletions

View File

@ -83,6 +83,11 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
if ( !isset($redirect['query']) )
$redirect['query'] = '';
// If the original URL ended with non-breaking spaces, they were almost
// certainly inserted by accident. Let's remove them, so the reader doesn't
// see a 404 error with no obvious cause.
$redirect['path'] = preg_replace( '|(%C2%A0)+$|i', '', $redirect['path'] );
// It's not a preview, so remove it from URL
if ( get_query_var( 'preview' ) ) {
$redirect['query'] = remove_query_arg( 'preview', $redirect['query'] );