Make WordPress Core


Ignore:
Timestamp:
07/29/2015 06:35:00 AM (11 years ago)
Author:
pento
Message:

WPDB: Remove some of the complexities in ::strip_invalid_text() associated with switching character sets between queries. Instead of trying to dynamically change connection character sets, we now rely on the value of ::charset. This also fixes the case where queries were being blocked when DB_CHARSET was utf8, but the column character set was non-utf8.

Merge of [33308] to the 4.1 branch.

See #32165.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/tests/phpunit/tests/db/charset.php

    r32402 r33478  
    244244                                'expected' => str_repeat( "\xcc\xe3", 5 ),
    245245                                'length'   => array( 'type' => 'byte', 'length' => 10 ),
     246                        ),
     247                        'ujis_with_utf8_connection' => array(
     248                                'charset'            => 'ujis',
     249                                'connection_charset' => 'utf8',
     250                                'value'              => '自動下書き',
     251                                'expected'           => '自動下書き',
     252                                'length'             => array( 'type' => 'byte', 'length' => 100 ),
     253                        ),
     254                        'ujis_with_utf8_connection_char_length' => array(
     255                                'charset'            => 'ujis',
     256                                'connection_charset' => 'utf8',
     257                                'value'              => '自動下書き',
     258                                'expected'           => '自動下書',
     259                                'length'             => array( 'type' => 'char', 'length' => 4 ),
     260                        ),
     261                        'ujis_with_utf8_connection_byte_length' => array(
     262                                'charset'            => 'ujis',
     263                                'connection_charset' => 'utf8',
     264                                'value'              => '自動下書き',
     265                                'expected'           => '自動',
     266                                'length'             => array( 'type' => 'byte', 'length' => 6 ),
    246267                        ),
    247268                        'false' => array(
    … …  
    290311                        $expected = $field;
    291312                        $expected['value'] = $expected['expected'];
    292                         unset( $expected['expected'], $field['expected'] );
     313                        unset( $expected['expected'], $field['expected'], $expected['connection_charset'] );
    293314
    294315                        // We're keeping track of these for our multiple-field test.
    … …  
    304325                }
    305326
    306                 // Time for our test of multiple fields at once.
    307                 $data_provider[] = array( $multiple, $multiple_expected, 'multiple fields/charsets' );
    308 
    309327                return $data_provider;
    310328        }
    … …  
    315333         */
    316334        function test_strip_invalid_text( $data, $expected, $message ) {
     335                $charset = self::$_wpdb->charset;
     336                if ( isset( $data[0]['connection_charset'] ) ) {
     337                        $new_charset = $data[0]['connection_charset'];
     338                        unset( $data[0]['connection_charset'] );
     339                } else {
     340                        $new_charset = $data[0]['charset'];
     341                }
     342
     343                self::$_wpdb->charset = $new_charset;
     344                self::$_wpdb->set_charset( self::$_wpdb->dbh, $new_charset );
     345
    317346                $actual = self::$_wpdb->strip_invalid_text( $data );
     347
     348                self::$_wpdb->charset = $charset;
     349                self::$_wpdb->set_charset( self::$_wpdb->dbh, $charset );
     350
    318351                $this->assertSame( $expected, $actual, $message );
    319352        }
Note: See TracChangeset for help on using the changeset viewer.