From 21eb85b469ca960a4a47f345434e8d61879f4436 Mon Sep 17 00:00:00 2001 From: markjaquith 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: http://svn.automattic.com/wordpress/trunk@9642 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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