Database: Hardening to bring `wpdb::prepare()` inline with documentation.
`wpdb::prepare()` supports %s, %d, and %F as placeholders in the query string. Any other non-escaped % will be escaped. Merges [41496] to 4.8 branch. Built from https://develop.svn.wordpress.org/branches/4.8@41497 git-svn-id: http://core.svn.wordpress.org/branches/4.8@41330 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7b17c71213
commit
1b16fc95d8
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.8.2-alpha-41484';
|
$wp_version = '4.8.2-alpha-41497';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
|
@ -1315,6 +1315,7 @@ class wpdb {
|
||||||
$query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
|
$query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
|
||||||
$query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware
|
$query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware
|
||||||
$query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s
|
$query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s
|
||||||
|
$query = preg_replace( '/%(?:%|$|([^dsF]))/', '%%\\1', $query ); // escape any unescaped percents
|
||||||
array_walk( $args, array( $this, 'escape_by_ref' ) );
|
array_walk( $args, array( $this, 'escape_by_ref' ) );
|
||||||
return @vsprintf( $query, $args );
|
return @vsprintf( $query, $args );
|
||||||
}
|
}
|
||||||
|
@ -2897,7 +2898,8 @@ class wpdb {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_array( $value['length'] ) ) {
|
if ( is_array( $value['length'] ) ) {
|
||||||
$queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING $connection_charset )", $value['value'], $value['length']['length'] );
|
$length = sprintf( '%.0f', $value['length']['length'] );
|
||||||
|
$queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), $length ) USING $connection_charset )", $value['value'] );
|
||||||
} else if ( 'binary' !== $charset ) {
|
} else if ( 'binary' !== $charset ) {
|
||||||
// If we don't have a length, there's no need to convert binary - it will always return the same result.
|
// If we don't have a length, there's no need to convert binary - it will always return the same result.
|
||||||
$queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value'] );
|
$queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value'] );
|
||||||
|
|
Loading…
Reference in New Issue