Make WordPress Core

Changeset 30375


Ignore:
Timestamp:
11/18/2014 03:37:23 AM (12 years ago)
Author:
pento
Message:

WPDB: When a db.php drop-in is being used, and it doesn't explicitly define itself as connecting to MySQL, skip the character set checks. This ensures that existing drop-ins won't accidentally run checks that they don't support.

See #21212.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r30366 r30375  
    22122212
    22132213                foreach ( $columns as $column ) {
    2214                         if ( $column->Collation ) {
     2214                        if ( ! empty( $column->Collation ) ) {
    22152215                                list( $charset ) = explode( '_', $column->Collation );
    22162216                                $charsets[ strtolower( $charset ) ] = true;
    … …  
    22382238                } elseif ( 0 === $count ) {
    22392239                        // No charsets, assume this table can store whatever.
    2240                         $charset = 'latin1';
     2240                        $charset = false;
    22412241                } else {
    22422242                        // More than one charset. Remove latin1 if present and recalculate.
    … …  
    22922292                }
    22932293
     2294                // Skip this entirely if this isn't a MySQL database.
     2295                if ( false === $this->is_mysql ) {
     2296                        return false;
     2297                }
     2298
    22942299                if ( empty( $this->table_charset[ $table ] ) ) {
    22952300                        // This primes column information for us.
    … …  
    23792384                        $charset = $value['charset'];
    23802385
    2381                         // latin1 will happily store anything.
    2382                         if ( 'latin1' === $charset ) {
     2386                        // Column isn't a string, or is latin1, which will will happily store anything.
     2387                        if ( false === $charset || 'latin1' === $charset ) {
    23832388                                continue;
    23842389                        }
    23852390
    2386                         // Column or value isn't a string.
    2387                         if ( false === $charset || ! is_string( $value['value'] ) ) {
     2391                        if ( ! is_string( $value['value'] ) ) {
    23882392                                continue;
    23892393                        }
  • trunk/tests/phpunit/tests/db/charset.php

    r30345 r30375  
    232232                array(
    233233                        'definition'      => '( a INT, b FLOAT )',
    234                         'table_expected'  => 'latin1',
     234                        'table_expected'  => false,
    235235                        'column_expected' => array( 'a' => false, 'b' => false )
    236236                ),
    … …  
    345345
    346346                self::$_wpdb->query( $drop );
     347        }
     348
     349        /**
     350         * @dataProvider data_test_get_column_charset
     351         * @ticket 21212
     352         */
     353        function test_get_column_charset_non_mysql( $drop, $create, $table, $columns ) {
     354                self::$_wpdb->query( $drop );
     355
     356                if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {
     357                        $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );
     358                        return;
     359                }
     360
     361                self::$_wpdb->is_mysql = false;
     362
     363                self::$_wpdb->query( $create );
     364
     365                $columns = array_keys( $columns );
     366                foreach ( $columns as $column => $charset ) {
     367                        $this->assertEquals( false, self::$_wpdb->get_col_charset( $table, $column ) );
     368                }
     369
     370                self::$_wpdb->query( $drop );
     371
     372                self::$_wpdb->is_mysql = true;
    347373        }
    348374
Note: See TracChangeset for help on using the changeset viewer.