Make WordPress Core


Ignore:
Timestamp:
11/17/2015 06:12:08 AM (10 years ago)
Author:
pento
Message:

WPDB: Fall back to the connection charset when sanity checking strings.

If DB_CHARSET isn't defined (or is empty), wpdb::$charset will be empty, too. wpdb::strip_invalid_text() assumes that it isn't empty, however, so we need to fall back to the connection character set when we're running our sanity checks.

Fixes #34708.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/db/charset.php

    r35186 r35655  
    866866        $this->assertEquals( $safe_query, $stripped_query );
    867867    }
     868
     869    /**
     870     * @ticket 34708
     871     */
     872    function test_no_db_charset_defined() {
     873        $tablename = 'test_cp1251_query_' . rand_str( 5 );
     874        if ( ! self::$_wpdb->query( "CREATE TABLE $tablename ( a VARCHAR(50) ) DEFAULT CHARSET 'cp1251'" ) ) {
     875            $this->markTestSkipped( "Test requires the 'cp1251' charset" );
     876        }
     877
     878        $charset = self::$_wpdb->charset;
     879        self::$_wpdb->charset = '';
     880
     881        $safe_query = "INSERT INTO $tablename( `a` ) VALUES( 'safe data' )";
     882        $stripped_query = self::$_wpdb->strip_invalid_text_from_query( $safe_query );
     883
     884        self::$_wpdb->query( "DROP TABLE $tablename" );
     885
     886        self::$_wpdb->charset = $charset;
     887
     888        $this->assertEquals( $safe_query, $stripped_query );
     889    }
    868890}
Note: See TracChangeset for help on using the changeset viewer.