Ticket #21212: 21212.diff
| File 21212.diff, 5.7 KB (added by , 11 years ago) |
|---|
-
src/wp-includes/wp-db.php
624 624 } 625 625 } 626 626 627 $this->init_charset();628 629 627 $this->dbuser = $dbuser; 630 628 $this->dbpassword = $dbpassword; 631 629 $this->dbname = $dbname; … … 727 725 728 726 if ( defined( 'DB_CHARSET' ) ) 729 727 $this->charset = DB_CHARSET; 728 729 if ( 'utf8' === $this->charset && $this->has_cap( 'utf8mb4' ) ) { 730 $this->charset = 'utf8mb4'; 731 } 732 733 if ( 'utf8mb4' === $this->charset && ( ! $this->collate || stripos( $this->collate, 'utf8_' ) === 0 ) ) { 734 $this->collate = 'utf8mb4_unicode_ci'; 735 } 730 736 } 731 737 732 738 /** … … 1477 1483 return false; 1478 1484 } else if ( $this->dbh ) { 1479 1485 $this->has_connected = true; 1486 1487 $this->init_charset(); 1480 1488 $this->set_charset( $this->dbh ); 1489 1481 1490 $this->ready = true; 1482 1491 $this->set_sql_mode(); 1483 1492 $this->select( $this->dbname, $this->dbh ); … … 2353 2362 'gb2312' => 'EUC-CN', 2354 2363 'ujis' => 'EUC-JP', 2355 2364 'utf32' => 'UTF-32', 2356 'utf8mb4' => 'UTF-8',2357 2365 ); 2358 2366 2359 2367 $supported_charsets = array(); … … 2388 2396 } 2389 2397 } 2390 2398 2391 // utf8 (mb3)can be handled by regex, which is a bunch faster than a DB lookup.2392 if ( 'utf8' === $charset || 'utf8mb3' === $charset ) {2399 // utf8 can be handled by regex, which is a bunch faster than a DB lookup. 2400 if ( 'utf8' === $charset || 'utf8mb3' === $charset || 'utf8mb4' === $charset ) { 2393 2401 $regex = '/ 2394 2402 ( 2395 2403 (?: [\x00-\x7F] # single-byte sequences 0xxxxxxx … … 2397 2405 | \xE0[\xA0-\xBF][\x80-\xBF] # triple-byte sequences 1110xxxx 10xxxxxx * 2 2398 2406 | [\xE1-\xEC][\x80-\xBF]{2} 2399 2407 | \xED[\x80-\x9F][\x80-\xBF] 2400 | [\xEE-\xEF][\x80-\xBF]{2} 2401 ){1,50} # ...one or more times 2408 | [\xEE-\xEF][\x80-\xBF]{2}'; 2409 2410 if ( 'utf8mb4' === $charset) { 2411 $regex .= ' 2412 | \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences 11110xxx 10xxxxxx * 3 2413 | [\xF1-\xF3][\x80-\xBF]{3} 2414 | \xF4[\x80-\x8F][\x80-\xBF]{2} 2415 '; 2416 } 2417 2418 $regex .= '){1,50} # ...one or more times 2402 2419 ) 2403 2420 | . # anything else 2404 2421 /x'; -
src/wp-admin/includes/upgrade.php
442 442 if ( $wp_current_db_version < 29630 ) 443 443 upgrade_400(); 444 444 445 if ( $wp_current_db_version < 30134 ) 446 upgrade_420(); 447 445 448 maybe_disable_link_manager(); 446 449 447 450 maybe_disable_automattic_widgets(); … … 1329 1332 } 1330 1333 1331 1334 /** 1335 * Execute changes made in WordPress 4.2.0. 1336 * 1337 * @since 4.2.0 1338 */ 1339 function upgrade_420() { 1340 global $wp_current_db_version, $wpdb; 1341 if ( $wp_current_db_version < 30134 && $wpdb->charset === 'utf8mb4') { 1342 if ( is_multisite() ) { 1343 $tables = $wpdb->tables; 1344 } else { 1345 $tables = array_merge( $wpdb->tables, $wpdb->global_tables ); 1346 } 1347 1348 foreach ( $tables as $table ) { 1349 $wpdb->query( "ALTER TABLE {$wpdb->$table} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" ); 1350 } 1351 } 1352 } 1353 1354 /** 1332 1355 * Execute network level changes 1333 1356 * 1334 1357 * @since 3.0.0 … … 1424 1447 update_site_option( 'illegal_names', $illegal_names ); 1425 1448 } 1426 1449 } 1450 1451 // 4.2 1452 if ( $wp_current_db_version < 30134 && $wpdb->charset === 'utf8mb4') { 1453 $tables = array_merge( $wpdb->ms_global_tables, $wpdb->global_tables ); 1454 1455 foreach ( $tables as $table ) { 1456 $wpdb->query( "ALTER TABLE {$wpdb->$table} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" ); 1457 } 1458 } 1427 1459 } 1428 1460 1429 1461 // The functions we use to actually do stuff -
src/wp-admin/setup-config.php
280 280 case 'DB_HOST' : 281 281 $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "');\r\n"; 282 282 break; 283 case 'DB_CHARSET' : 284 if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset && $wpdb->has_cap( 'utf8mb4' ) ) ) { 285 $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'utf8mb4');\r\n"; 286 } 287 break; 283 288 case 'AUTH_KEY' : 284 289 case 'SECURE_AUTH_KEY' : 285 290 case 'LOGGED_IN_KEY' : -
tests/phpunit/tests/db/charset.php
130 130 } 131 131 132 132 /** 133 * @ ticket 21212133 * @ticket 21212 134 134 */ 135 135 function test_process_fields_failure() { 136 136 global $wpdb; 137 $data = array( 'post_content' => "H€llo\xf0\x9f\x98\x88World¢" ); 137 // \xf0\xff\xff\xff is invalid in utf8 and utf8mb4 138 $data = array( 'post_content' => "H€llo\xf0\xff\xff\xffWorld¢" ); 138 139 $this->assertFalse( self::$_wpdb->process_fields( $wpdb->posts, $data, null ) ); 139 140 } 140 141 … … 436 437 */ 437 438 function test_invalid_characters_in_query() { 438 439 global $wpdb; 439 $this->assertFalse( $wpdb->query( "INSERT INTO {$wpdb->posts} (post_content) VALUES ('foo\xf0\x 9f\x98\x88bar')" ) );440 $this->assertFalse( $wpdb->query( "INSERT INTO {$wpdb->posts} (post_content) VALUES ('foo\xf0\xff\xff\xffbar')" ) ); 440 441 } 441 442 } -
src/wp-includes/version.php
11 11 * 12 12 * @global int $wp_db_version 13 13 */ 14 $wp_db_version = 3013 3;14 $wp_db_version = 30134; 15 15 16 16 /** 17 17 * Holds the TinyMCE version