WPDB: When deciding if a query needs extra sanity checking based on collation, return early when we can. Merges [32232] and [32233] to the 4.0 branch.

See #32029.


Built from https://develop.svn.wordpress.org/branches/4.0@32235


git-svn-id: http://core.svn.wordpress.org/branches/4.0@32209 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2015-04-21 06:19:40 +00:00
parent 530a462ba1
commit e20485b9cb
1 changed files with 20 additions and 1 deletions

View File

@ -2371,20 +2371,38 @@ class wpdb {
if ( $this->checking_collation ) { if ( $this->checking_collation ) {
return true; return true;
} }
// We don't need to check the collation for queries that don't read data.
$query = ltrim( $query, "\r\n\t (" );
if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN)\s/i', $query ) ) {
return true;
}
// All-ASCII queries don't need extra checking.
if ( $this->check_ascii( $query ) ) {
return true;
}
$table = $this->get_table_from_query( $query ); $table = $this->get_table_from_query( $query );
if ( ! $table ) { if ( ! $table ) {
return false; return false;
} }
$this->checking_collation = true; $this->checking_collation = true;
$this->get_table_charset( $table ); $collation = $this->get_table_charset( $table );
$this->checking_collation = false; $this->checking_collation = false;
// Tables with no collation, or latin1 only, don't need extra checking.
if ( false === $collation || 'latin1' === $collation ) {
return true;
}
$table = strtolower( $table ); $table = strtolower( $table );
if ( empty( $this->col_meta[ $table ] ) ) { if ( empty( $this->col_meta[ $table ] ) ) {
return false; return false;
} }
// If any of the columns don't have one of these collations, it needs more sanity checking.
foreach( $this->col_meta[ $table ] as $col ) { foreach( $this->col_meta[ $table ] as $col ) {
if ( empty( $col->Collation ) ) { if ( empty( $col->Collation ) ) {
continue; continue;
@ -2412,6 +2430,7 @@ class wpdb {
* such as 'field' are retained in each value array. If we cannot * such as 'field' are retained in each value array. If we cannot
* remove invalid characters, a {@see WP_Error} object is returned. * remove invalid characters, a {@see WP_Error} object is returned.
*/ */
// If any of the columns don't have one of these collations, it needs more sanity checking.
protected function strip_invalid_text( $data ) { protected function strip_invalid_text( $data ) {
// Some multibyte character sets that we can check in PHP. // Some multibyte character sets that we can check in PHP.
$mb_charsets = array( $mb_charsets = array(