Skip to content

Commit 78ced47

Browse files
committed
Grouped backports to the 5.0 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 5.0 branch. Props vortfu, dd32, ehtis, zieladam, whyisjake, xknown, peterwilsoncc, desrosj, iandunn. git-svn-id: https://develop.svn.wordpress.org/branches/5.0@52473 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d98a039 commit 78ced47

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
@@ -1325,8 +1325,8 @@ function upgrade_280() {
13251325
$start = 0;
13261326
while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
13271327
foreach ( $rows as $row ) {
1328-
$value = $row->option_value;
1329-
if ( !@unserialize( $value ) )
1328+
$value = maybe_unserialize( $row->option_value );
1329+
if ( $value === $row->option_value )
13301330
$value = stripslashes( $value );
13311331
if ( $value !== $row->option_value ) {
13321332
update_option( $row->option_name, $value );

src/wp-includes/class-wp-meta-query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ protected function find_compatible_table_alias( $clause, $parent_query ) {
695695
$clause_compare = strtoupper( $clause['compare'] );
696696
$sibling_compare = strtoupper( $sibling['compare'] );
697697
if ( in_array( $clause_compare, $compatible_compares ) && in_array( $sibling_compare, $compatible_compares ) ) {
698-
$alias = $sibling['alias'];
698+
$alias = preg_replace( '/\W/', '_', $sibling['alias'] );
699699
break;
700700
}
701701
}

src/wp-includes/class-wp-tax-query.php

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

528528
// The sibling must both have compatible operator to share its alias.
529529
if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
530-
$alias = $sibling['alias'];
530+
$alias = preg_replace( '/\W/', '_', $sibling['alias'] );
531531
break;
532532
}
533533
}
@@ -556,7 +556,11 @@ private function clean_query( &$query ) {
556556
return;
557557
}
558558

559-
$query['terms'] = array_unique( (array) $query['terms'] );
559+
if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
560+
$query['terms'] = array_unique( (array) $query['terms'] );
561+
} else {
562+
$query['terms'] = wp_parse_id_list( $query['terms'] );
563+
}
560564

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

src/wp-includes/formatting.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,12 +1084,14 @@ function wp_check_invalid_utf8( $string, $strip = false ) {
10841084
* Encode the Unicode values to be used in the URI.
10851085
*
10861086
* @since 1.5.0
1087+
* @since 5.8.3 Added the `encode_ascii_characters` parameter.
10871088
*
1088-
* @param string $utf8_string
1089-
* @param int $length Max length of the string
1089+
* @param string $utf8_string String to encode.
1090+
* @param int $length Max length of the string
1091+
* @param bool $encode_ascii_characters Whether to encode ascii characters such as < " '
10901092
* @return string String with Unicode encoded for URI.
10911093
*/
1092-
function utf8_uri_encode( $utf8_string, $length = 0 ) {
1094+
function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters = false ) {
10931095
$unicode = '';
10941096
$values = array();
10951097
$num_octets = 1;
@@ -1104,11 +1106,14 @@ function utf8_uri_encode( $utf8_string, $length = 0 ) {
11041106
$value = ord( $utf8_string[ $i ] );
11051107

11061108
if ( $value < 128 ) {
1107-
if ( $length && ( $unicode_length >= $length ) ) {
1109+
$char = chr( $value );
1110+
$encoded_char = $encode_ascii_characters ? rawurlencode( $char ) : $char;
1111+
$encoded_char_length = strlen( $encoded_char );
1112+
if ( $length && ( $unicode_length + $encoded_char_length ) > $length ) {
11081113
break;
11091114
}
1110-
$unicode .= chr( $value );
1111-
$unicode_length++;
1115+
$unicode .= $encoded_char;
1116+
$unicode_length += $encoded_char_length;
11121117
} else {
11131118
if ( count( $values ) == 0 ) {
11141119
if ( $value < 224 ) {

src/wp-includes/post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4059,7 +4059,7 @@ function _truncate_post_slug( $slug, $length = 200 ) {
40594059
if ( $decoded_slug === $slug )
40604060
$slug = substr( $slug, 0, $length );
40614061
else
4062-
$slug = utf8_uri_encode( $decoded_slug, $length );
4062+
$slug = utf8_uri_encode( $decoded_slug, $length, true );
40634063
}
40644064

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

0 commit comments

Comments
 (0)