Skip to content

Commit f42dd48

Browse files
committed
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
1 parent 41cb4b0 commit f42dd48

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

src/wp-admin/includes/upgrade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,8 @@ function upgrade_280() {
12061206
$start = 0;
12071207
while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
12081208
foreach( $rows as $row ) {
1209-
$value = $row->option_value;
1210-
if ( !@unserialize( $value ) )
1209+
$value = maybe_unserialize( $row->option_value );
1210+
if ( $value === $row->option_value )
12111211
$value = stripslashes( $value );
12121212
if ( $value !== $row->option_value ) {
12131213
update_option( $row->option_name, $value );

src/wp-includes/formatting.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,14 @@ function wp_check_invalid_utf8( $string, $strip = false ) {
998998
* Encode the Unicode values to be used in the URI.
999999
*
10001000
* @since 1.5.0
1001+
* @since 5.8.3 Added the `encode_ascii_characters` parameter.
10011002
*
1002-
* @param string $utf8_string
1003-
* @param int $length Max length of the string
1003+
* @param string $utf8_string String to encode.
1004+
* @param int $length Max length of the string
1005+
* @param bool $encode_ascii_characters Whether to encode ascii characters such as < " '
10041006
* @return string String with Unicode encoded for URI.
10051007
*/
1006-
function utf8_uri_encode( $utf8_string, $length = 0 ) {
1008+
function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
10071009
$unicode = '';
10081010
$values = array();
10091011
$num_octets = 1;
@@ -1018,11 +1020,14 @@ function utf8_uri_encode( $utf8_string, $length = 0 ) {
10181020
$value = ord( $utf8_string[ $i ] );
10191021

10201022
if ( $value < 128 ) {
1021-
if ( $length && ( $unicode_length >= $length ) ) {
1023+
$char = chr( $value );
1024+
$encoded_char = $encode_ascii_characters ? rawurlencode( $char ) : $char;
1025+
$encoded_char_length = strlen( $encoded_char );
1026+
if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
10221027
break;
10231028
}
1024-
$unicode .= chr( $value );
1025-
$unicode_length++;
1029+
$unicode .= $encoded_char;
1030+
$unicode_length += $encoded_char_length;
10261031
} else {
10271032
if ( count( $values ) == 0 ) {
10281033
if ( $value < 224 ) {

src/wp-includes/meta.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ protected function find_compatible_table_alias( $clause, $parent_query ) {
15711571
$clause_compare = strtoupper( $clause['compare'] );
15721572
$sibling_compare = strtoupper( $sibling['compare'] );
15731573
if ( in_array( $clause_compare, $compatible_compares ) && in_array( $sibling_compare, $compatible_compares ) ) {
1574-
$alias = $sibling['alias'];
1574+
$alias = preg_replace( '/\W/', '_', $sibling['alias'] );
15751575
break;
15761576
}
15771577
}

src/wp-includes/post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3894,7 +3894,7 @@ function _truncate_post_slug( $slug, $length = 200 ) {
38943894
if ( $decoded_slug === $slug )
38953895
$slug = substr( $slug, 0, $length );
38963896
else
3897-
$slug = utf8_uri_encode( $decoded_slug, $length );
3897+
$slug = utf8_uri_encode( $decoded_slug, $length, true );
38983898
}
38993899

39003900
return rtrim( $slug, '-' );

src/wp-includes/taxonomy.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ protected function find_compatible_table_alias( $clause, $parent_query ) {
11861186

11871187
// The sibling must both have compatible operator to share its alias.
11881188
if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
1189-
$alias = $sibling['alias'];
1189+
$alias = preg_replace( '/\W/', '_', $sibling['alias'] );
11901190
break;
11911191
}
11921192
}
@@ -1216,7 +1216,11 @@ private function clean_query( &$query ) {
12161216
return;
12171217
}
12181218

1219-
$query['terms'] = array_unique( (array) $query['terms'] );
1219+
if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
1220+
$query['terms'] = array_unique( (array) $query['terms'] );
1221+
} else {
1222+
$query['terms'] = wp_parse_id_list( $query['terms'] );
1223+
}
12201224

12211225
if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
12221226
$this->transform_query( $query, 'term_id' );

0 commit comments

Comments
 (0)