Make WordPress Core

Changeset 54229

09/19/2022 11:46:26 PM (18 months ago)

Date/Time: Correct sanitization of timezone_string in sanitize_option().

This fixes a bug where if the timezone_string is set to a timezone name which has since been deprecated, the option value would be “lost” when saving the value again, as the comparison being done to verify whether it is a valid timezone name would only take “current” timezone names into account and would invalidate deprecated timezone names.

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 adding a dedicated test to the data provider used in the Tests_Option_SanitizeOption test class.

Note: The new data set is named, even though the other data sets are unnamed, to make sure it is clear what this data set is testing. Adding test names for the original data sets in this data provider would be a great future improvement, but is outside of the scope of this commit.

Follow-up to [18323], [33119], [54207], [54217], [54227].

Props jrf, costdev.
See #56468.

2 edited


  • trunk/src/wp-includes/formatting.php

    r53776 r54229  
    49254925        case 'timezone_string':
    4926             $allowed_zones = timezone_identifiers_list();
     4926            $allowed_zones = timezone_identifiers_list( DateTimeZone::ALL_WITH_BC );
    49274927            if ( ! in_array( $value, $allowed_zones, true ) && ! empty( $value ) ) {
    49284928                $error = __( 'The timezone you have entered is not valid. Please select a valid timezone.' );
  • trunk/tests/phpunit/tests/option/sanitizeOption.php

    r53865 r54229  
    7070            array( 'timezone_string', 'Europe/London', 'Europe/London' ),
    7171            array( 'timezone_string', get_option( 'timezone_string' ), 'invalid' ),
     72            // @ticket 56468
     73            'deprecated timezone string is accepted as valid' => array(
     74                'option_name' => 'timezone_string',
     75                'sanitized'   => 'America/Buenos_Aires',
     76                'original'    => 'America/Buenos_Aires',
     77            ),
    7278            array( 'permalink_structure', '', '' ),
    7379            array( 'permalink_structure', '/%year%/%20%postname%', '/%year%/ %postname%' ),
Note: See TracChangeset for help on using the changeset viewer.