From f6120877dfc5bc68391cc83d460ee1a34a5af5e4 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 20 Mar 2015 01:02:28 +0000 Subject: [PATCH] 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 Built from https://develop.svn.wordpress.org/trunk@31838 git-svn-id: http://core.svn.wordpress.org/trunk@31820 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index e4d87f95f1..5f4bda087e 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -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'] );