Make WordPress Core

Ticket #44767: 44767-ignore_change_with_space_between_column_and_type.diff

File 44767-ignore_change_with_space_between_column_and_type.diff, 1.5 KB (added by soulseekah, 7 years ago)
  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index 85439b4..7368b46 100644
    function dbDelta( $queries = '', $execute = true ) { 
    26702670                        if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
    26712671
    26722672                                // Get the field type from the query.
    2673                                 preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
     2673                                preg_match( '|`?' . $tablefield->Field . '`?\s+([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
    26742674                                $fieldtype            = $matches[1];
    26752675                                $fieldtype_lowercased = strtolower( $fieldtype );
    26762676
  • tests/phpunit/tests/dbdelta.php

    diff --git tests/phpunit/tests/dbdelta.php tests/phpunit/tests/dbdelta.php
    index 1e9c93f..c1b64cc 100644
    class Tests_dbDelta extends WP_UnitTestCase { 
    996996                        $updates
    997997                );
    998998        }
     999
     1000        /**
     1001         * @ticket 44767
     1002         */
     1003        function test_ignore_change_with_space_between_column_and_type() {
     1004                global $wpdb;
     1005
     1006                $schema = "
     1007                        CREATE TABLE {$wpdb->prefix}dbdelta_test3 (
     1008                                `foo-bar`      varchar(255) DEFAULT NULL
     1009                        )
     1010                ";
     1011
     1012                $wpdb->query( $schema );
     1013
     1014                $schema_update = "
     1015                        CREATE TABLE {$wpdb->prefix}dbdelta_test3 (
     1016                                `foo-bar`      varchar(255) DEFAULT NULL
     1017                        )
     1018                ";
     1019
     1020                $updates = dbDelta( $schema_update );
     1021
     1022                $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test3" );
     1023
     1024                $this->assertEmpty( $updates );
     1025        }
    9991026}