From 3f51df65e0d221a83d25991772ec322e031aa0d8 Mon Sep 17 00:00:00 2001
From: nacin <nacin@1a063a9b-81f0-0310-95a4-ce76da25c4cd>
Date: Fri, 27 Apr 2012 15:40:00 +0000
Subject: [PATCH] Run rawurlencode_deep() through the parsed query in
 canonical. (Introduces rawurlencode_deep().) props toppa for the initial
 patch. fixes #20143.

git-svn-id: http://svn.automattic.com/wordpress/trunk@20611 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
 wp-includes/canonical.php  |  2 +-
 wp-includes/formatting.php | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php
index b4d1907188..490e0a638a 100644
--- a/wp-includes/canonical.php
+++ b/wp-includes/canonical.php
@@ -301,7 +301,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
 				unset( $_parsed_query['name'] );
 		}
 
-		$_parsed_query = array_map( 'rawurlencode', $_parsed_query );
+		$_parsed_query = rawurlencode_deep( $_parsed_query );
 		$redirect_url = add_query_arg( $_parsed_query, $redirect_url );
 	}
 
diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index a02fd17e1c..31256b8f1f 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -1339,8 +1339,6 @@ function stripslashes_deep($value) {
 /**
  * Navigates through an array and encodes the values to be used in a URL.
  *
- * Uses a callback to pass the value of the array back to the function as a
- * string.
  *
  * @since 2.2.0
  *
@@ -1352,6 +1350,18 @@ function urlencode_deep($value) {
 	return $value;
 }
 
+/**
+ * Navigates through an array and raw encodes the values to be used in a URL.
+ *
+ * @since 3.4.0
+ *
+ * @param array|string $value The array or string to be encoded.
+ * @return array|string $value The encoded array (or string from the callback).
+ */
+function rawurlencode_deep( $value ) {
+	return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode( $value );
+}
+
 /**
  * Converts email addresses characters to HTML entities to block spam bots.
  *