WordPress.org

Make WordPress Core

Changeset 38580


Ignore:
Timestamp:
09/08/2016 11:48:05 PM (21 months ago)
Author:
pento
Message:

Database: Fall back to utf8 when utf8mb4 isn't supported.

Sometimes, DB_CHARSET will be set to utf8mb4, even if the current setup doesn't support utf8mb4. After [38442], this can cause significant character set failures, causing the connection to fall back to latin1.

Instead of doing this, we now check that the connection supports utf8mb4 before trying to use it, and fall back to utf8 when we need to.

Fixes #37982 for trunk.

Location:
trunk
Files:
2 edited

Legend:

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

    r38507 r38580  
    778778        if ( 'utf8' === $charset && $this->has_cap( 'utf8mb4' ) ) {
    779779            $charset = 'utf8mb4';
     780        }
     781
     782        if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) {
     783            $charset = 'utf8';
     784            $collate = str_replace( 'utf8mb4_', 'utf8_', $collate );
    780785        }
    781786
  • trunk/tests/phpunit/tests/db.php

    r38507 r38580  
    10321032        $this->assertSame( 'utf8mb4_swedish_ci', $result['collate'] );
    10331033    }
     1034
     1035    /**
     1036     * @ticket 37982
     1037     */
     1038    function test_charset_switched_to_utf8() {
     1039        global $wpdb;
     1040
     1041        if ( $wpdb->has_cap( 'utf8mb4' ) ) {
     1042            $this->markTestSkipped( 'This test requires utf8mb4 to not be supported.' );
     1043        }
     1044
     1045        $charset = 'utf8mb4';
     1046        $collate = 'utf8mb4_general_ci';
     1047
     1048        $result = $wpdb->determine_charset( $charset, $collate );
     1049
     1050        $this->assertSame( 'utf8', $result['charset'] );
     1051        $this->assertSame( 'utf8_general_ci', $result['collate'] );
     1052    }
    10341053}
Note: See TracChangeset for help on using the changeset viewer.