From e383920415bdc142ffc753cccb7213697b5aa9a4 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Wed, 12 Nov 2008 20:09:16 +0000 Subject: [PATCH] Be more picky about the trailing blank query string things we strip. props filosofo, fitztrev, stevish, azaozz, DD32 (go team!). fixes #8098. fixes #8180 git-svn-id: https://develop.svn.wordpress.org/trunk@9642 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/canonical.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index ecd48ce3b4..1469dcf15d 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -200,11 +200,14 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { $redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] ); if ( !empty( $redirect['query'] ) ) { - // Remove trailing slashes from certain terminating query string args + // Remove trailing spaces from certain terminating query string args $redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] ); // Clean up empty query strings - $redirect['query'] = preg_replace( '#&?(p|page_id|cat|tag)=?$#', '', $redirect['query'] ); + $redirect['query'] = preg_replace( '#(^\??|&)(p|page_id|cat|tag)=?$#', '', $redirect['query'] ); + + // Remove redundant leading ampersands + $redirect['query'] = preg_replace( '#^\??&+#', '', $redirect['query'] ); } // strip /index.php/ when we're not using PATHINFO permalinks