Database: Hardening for `wpdb::prepare()`
Previously if you passed an array of values for placeholders, additional values could be passed as well. Now additional values will be ignored. Merges [41470] to 4.0 branch. Built from https://develop.svn.wordpress.org/branches/4.0@41479 git-svn-id: http://core.svn.wordpress.org/branches/4.0@41312 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d29f744559
commit
f80bd53e4b
|
@ -1207,9 +1207,18 @@ class wpdb {
|
||||||
|
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
array_shift( $args );
|
array_shift( $args );
|
||||||
|
|
||||||
// If args were passed as an array (as in vsprintf), move them up
|
// If args were passed as an array (as in vsprintf), move them up
|
||||||
if ( isset( $args[0] ) && is_array($args[0]) )
|
if ( is_array( $args[0] ) && count( $args ) == 1 ) {
|
||||||
$args = $args[0];
|
$args = $args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $args as $arg ) {
|
||||||
|
if ( ! is_scalar( $arg ) ) {
|
||||||
|
_doing_it_wrong( 'wpdb::prepare', sprintf( 'Unsupported value type (%s).', gettype( $arg ) ), '4.0.19' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
|
$query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
|
||||||
$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
|
||||||
|
|
Loading…
Reference in New Issue