Make WordPress Core


Ignore:
Timestamp:
09/20/2022 12:41:58 AM (2 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Correct sanitization of localized default timezone_string in populate_options().

This fixes a bug where if the default timezone_string is set to a deprecated timezone name due to a localization providing an outdated timezone name string, this localized timezone string would be discarded and an empty string would be set as the timezone value instead.

By passing the DateTimeZone::ALL_WITH_BC constant as the $timezoneGroup parameter to the PHP native timezone_identifiers_list() function, a timezone name list is retrieved containing both current and deprecated timezone names, preventing the invalidation of the option value.

See the extensive write-up about this in ticket #56468.

Also see: PHP Manual: timezone_identifiers_list().

Includes:

  • Expanding the translators comment to encourage translators to use “old” names over “new” names.
  • Adding a dedicated test to the Tests_Admin_IncludesSchema test class.

Follow-up to [54207], [54217], [54227], [54229], [54230].

Props jrf, costdev.
See #56468.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesSchema.php

    r52010 r54232  
    179179
    180180    /**
     181     * Ensures that deprecated timezone strings set as a default in a translation are handled correctly.
     182     *
     183     * @ticket 56468
     184     */
     185    public function test_populate_options_when_locale_uses_deprecated_timezone_string() {
     186        global $wpdb;
     187
     188        // Back up.
     189        $orig_options  = $wpdb->options;
     190        $wpdb->options = self::$options;
     191
     192        // Set the "default" value for the timezone to a deprecated timezone.
     193        add_filter(
     194            'gettext_with_context',
     195            static function( $translation, $text, $context ) {
     196                if ( '0' === $text && 'default GMT offset or timezone string' === $context ) {
     197                    return 'America/Buenos_Aires';
     198                }
     199
     200                return $translation;
     201            },
     202            10,
     203            3
     204        );
     205
     206        // Test.
     207        populate_options();
     208
     209        wp_cache_delete( 'alloptions', 'options' );
     210
     211        $result = get_option( 'timezone_string' );
     212
     213        // Reset.
     214        $wpdb->query( "TRUNCATE TABLE {$wpdb->options}" );
     215        $wpdb->options = $orig_options;
     216
     217        // Assert.
     218        $this->assertSame( 'America/Buenos_Aires', $result );
     219    }
     220
     221    /**
    181222     * @ticket 44896
    182223     * @group multisite
Note: See TracChangeset for help on using the changeset viewer.