Make WordPress Core

Ticket #44767: 44767.diff

File 44767.diff, 2.4 KB (added by soulseekah, 7 years ago)

2-in-1

  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index 85439b4..71711ae 100644
    function dbDelta( $queries = '', $execute = true ) { 
    25532553                        $validfield = true;
    25542554                        switch ( $fieldname_lowercased ) {
    25552555                                case '':
     2556                                        continue 2;
    25562557                                case 'primary':
    25572558                                case 'index':
    25582559                                case 'fulltext':
    function dbDelta( $queries = '', $execute = true ) { 
    26702671                        if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
    26712672
    26722673                                // Get the field type from the query.
    2673                                 preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
     2674                                preg_match( '|`?' . $tablefield->Field . '`?\s+([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
    26742675                                $fieldtype            = $matches[1];
    26752676                                $fieldtype_lowercased = strtolower( $fieldtype );
    26762677
  • tests/phpunit/tests/dbdelta.php

    diff --git tests/phpunit/tests/dbdelta.php tests/phpunit/tests/dbdelta.php
    index 1e9c93f..398136b 100644
    class Tests_dbDelta extends WP_UnitTestCase { 
    996996                        $updates
    997997                );
    998998        }
     999
     1000        /**
     1001         * @ticket 44767
     1002         * @ticket 36924
     1003         */
     1004        function test_ignore_change_with_space_between_column_and_type() {
     1005                global $wpdb;
     1006
     1007                $schema = "
     1008                        CREATE TABLE {$wpdb->prefix}dbdelta_test3 (
     1009                                `foo-bar`      varchar(255) DEFAULT NULL
     1010                        )
     1011                ";
     1012
     1013                $wpdb->query( $schema );
     1014
     1015                $schema_update = "
     1016                        CREATE TABLE {$wpdb->prefix}dbdelta_test3 (
     1017                                `foo-bar`      varchar(255) DEFAULT NULL
     1018                        )
     1019                ";
     1020
     1021                $updates = dbDelta( $schema_update );
     1022
     1023                $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test3" );
     1024
     1025                $this->assertEmpty( $updates );
     1026        }
     1027
     1028        /**
     1029         * @ticket 44767
     1030         */
     1031        function test_ignore_empty_lines_completely() {
     1032                global $wpdb;
     1033
     1034                $schema = "
     1035                        CREATE TABLE {$wpdb->prefix}dbdelta_test4 (
     1036                                `foo-bar` varchar(255) DEFAULT NULL,
     1037
     1038                                `foo-baz` varchar(255) DEFAULT NULL
     1039                        )
     1040                ";
     1041
     1042                $wpdb->query( $schema );
     1043
     1044                $schema_update = "
     1045                        CREATE TABLE {$wpdb->prefix}dbdelta_test4 (
     1046                                `foo-bar` varchar(255) DEFAULT NULL,
     1047
     1048
     1049
     1050                                `foo-baz` varchar(255) DEFAULT NULL
     1051                        )
     1052                ";
     1053
     1054                $updates = dbDelta( $schema_update );
     1055
     1056                $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test4" );
     1057
     1058                $this->assertEmpty( $updates );
     1059        }
    9991060}