From a6cb4b293c52a01601b7228774f3d327b1991b53 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 17 Jul 2015 07:07:26 +0000 Subject: [PATCH] WPDB: `::strip_text_from_query()` doesn't pass a length to `::strip_invalid_text()`, which was causing queries to fail when they contained characters that needed to be sanity checked by MySQL. Props dd32, mdawaffe, pento. Fixes #32279. Built from https://develop.svn.wordpress.org/trunk@33310 git-svn-id: http://core.svn.wordpress.org/trunk@33282 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-includes/wp-db.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index 43b3506c58..9aaf6ea048 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-beta3-33308'; +$wp_version = '4.3-beta3-33310'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index d6f5a6679b..c480e46d68 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -2629,8 +2629,13 @@ class wpdb { if ( is_array( $value['length'] ) ) { $length = $value['length']['length']; + $truncate_by_byte_length = 'byte' === $value['length']['type']; } else { $length = false; + // Since we have no length, we'll never truncate. + // Initialize the variable to false. true would take us + // through an unnecessary (for this case) codepath below. + $truncate_by_byte_length = false; } // There's no charset to work with. @@ -2643,8 +2648,6 @@ class wpdb { continue; } - $truncate_by_byte_length = 'byte' === $value['length']['type']; - $needs_validation = true; if ( // latin1 can store any byte sequence @@ -2718,7 +2721,12 @@ class wpdb { $charset = $value['charset']; } - $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset} )", $value['value'], $value['length']['length'] ); + if ( is_array( $value['length'] ) ) { + $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset} )", $value['value'], $value['length']['length'] ); + } 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. + $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING {$this->charset} )", $value['value'] ); + } unset( $data[ $col ]['db'] ); }