summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJonathan Desrosiers <desrosj@git.wordpress.org>2022-01-06 18:19:09 +0000
committerJonathan Desrosiers <desrosj@git.wordpress.org>2022-01-06 18:19:09 +0000
commitf42dd489dcc6eaf9c99da8ceb235e9766eae854e (patch)
tree290ecdae6fa5ab762b4047a968e12ae62a444f57
parent41cb4b0b0b8d4d122dce69a4cb57f5db1e4b1ac2 (diff)
downloadwordpress-f42dd489dcc6eaf9c99da8ceb235e9766eae854e.tar.gz
wordpress-f42dd489dcc6eaf9c99da8ceb235e9766eae854e.zip
Grouped backports to the 4.3 branch.
- Query: Improve sanitization within `WP_Tax_Query`. - Query: Improve sanitization within `WP_Meta_Query`. - Upgrade/Install: Avoid using `unserialize()` unnecessarily. - Formatting: Correctly encode ASCII characters in post slugs. Merges [52454-52457] to the 4.3 branch. Props vortfu, dd32, ehtis, zieladam, whyisjake, xknown, peterwilsoncc, desrosj, iandunn. git-svn-id: https://develop.svn.wordpress.org/branches/4.3@52480 602fd350-edb4-49c9-b593-d223f7449a82
-rw-r--r--src/wp-admin/includes/upgrade.php4
-rw-r--r--src/wp-includes/formatting.php17
-rw-r--r--src/wp-includes/meta.php2
-rw-r--r--src/wp-includes/post.php2
-rw-r--r--src/wp-includes/taxonomy.php8
5 files changed, 21 insertions, 12 deletions
diff --git a/src/wp-admin/includes/upgrade.php b/src/wp-admin/includes/upgrade.php
index 2c1b543607..617fec374b 100644
--- a/src/wp-admin/includes/upgrade.php
+++ b/src/wp-admin/includes/upgrade.php
@@ -1206,8 +1206,8 @@ function upgrade_280() {
$start = 0;
while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
foreach( $rows as $row ) {
- $value = $row->option_value;
- if ( !@unserialize( $value ) )
+ $value = maybe_unserialize( $row->option_value );
+ if ( $value === $row->option_value )
$value = stripslashes( $value );
if ( $value !== $row->option_value ) {
update_option( $row->option_name, $value );
diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index e1842f18aa..2e1cb1e8ff 100644
--- a/src/wp-includes/formatting.php
+++ b/src/wp-includes/formatting.php
@@ -998,12 +998,14 @@ function wp_check_invalid_utf8( $string, $strip = false ) {
* Encode the Unicode values to be used in the URI.
*
* @since 1.5.0
+ * @since 5.8.3 Added the `encode_ascii_characters` parameter.
*
- * @param string $utf8_string
- * @param int $length Max length of the string
+ * @param string $utf8_string String to encode.
+ * @param int $length Max length of the string
+ * @param bool $encode_ascii_characters Whether to encode ascii characters such as < " '
* @return string String with Unicode encoded for URI.
*/
-function utf8_uri_encode( $utf8_string, $length = 0 ) {
+function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
$unicode = '';
$values = array();
$num_octets = 1;
@@ -1018,11 +1020,14 @@ function utf8_uri_encode( $utf8_string, $length = 0 ) {
$value = ord( $utf8_string[ $i ] );
if ( $value < 128 ) {
- if ( $length && ( $unicode_length >= $length ) ) {
+ $char = chr( $value );
+ $encoded_char = $encode_ascii_characters ? rawurlencode( $char ) : $char;
+ $encoded_char_length = strlen( $encoded_char );
+ if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
break;
}
- $unicode .= chr( $value );
- $unicode_length++;
+ $unicode .= $encoded_char;
+ $unicode_length += $encoded_char_length;
} else {
if ( count( $values ) == 0 ) {
if ( $value < 224 ) {
diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php
index 0eadb902b1..a18decaa20 100644
--- a/src/wp-includes/meta.php
+++ b/src/wp-includes/meta.php
@@ -1571,7 +1571,7 @@ class WP_Meta_Query {
$clause_compare = strtoupper( $clause['compare'] );
$sibling_compare = strtoupper( $sibling['compare'] );
if ( in_array( $clause_compare, $compatible_compares ) && in_array( $sibling_compare, $compatible_compares ) ) {
- $alias = $sibling['alias'];
+ $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
break;
}
}
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index da2f1839c9..79c372b1f4 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -3894,7 +3894,7 @@ function _truncate_post_slug( $slug, $length = 200 ) {
if ( $decoded_slug === $slug )
$slug = substr( $slug, 0, $length );
else
- $slug = utf8_uri_encode( $decoded_slug, $length );
+ $slug = utf8_uri_encode( $decoded_slug, $length, true );
}
return rtrim( $slug, '-' );
diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php
index 7ad0334844..fbbe6ca2b3 100644
--- a/src/wp-includes/taxonomy.php
+++ b/src/wp-includes/taxonomy.php
@@ -1186,7 +1186,7 @@ class WP_Tax_Query {
// The sibling must both have compatible operator to share its alias.
if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
- $alias = $sibling['alias'];
+ $alias = preg_replace( '/\W/', '_', $sibling['alias'] );
break;
}
}
@@ -1216,7 +1216,11 @@ class WP_Tax_Query {
return;
}
- $query['terms'] = array_unique( (array) $query['terms'] );
+ if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
+ $query['terms'] = array_unique( (array) $query['terms'] );
+ } else {
+ $query['terms'] = wp_parse_id_list( $query['terms'] );
+ }
if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
$this->transform_query( $query, 'term_id' );