Make WordPress Core


Ignore:
Timestamp:
06/23/2023 04:01:08 PM (19 months ago)
Author:
swissspidy
Message:

I18N: Ensure determine_locale() does not potentially return an empty string.

Call get_locale() as a last resort in case the sanitized locale is an empty string.

Also swaps conditionals to cater for more typical use case and adds tests.

Follow-up to [55862]

Props Cybr, swissspidy.
Fixes #58317.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n/determineLocale.php

    r55862 r56003  
    212212    }
    213213
     214    public function test_wp_login_get_param_on_login_page_incorrect_string() {
     215        add_filter(
     216            'locale',
     217            static function() {
     218                return 'siteLocale';
     219            }
     220        );
     221
     222        wp_set_current_user( self::$user_id );
     223
     224        $GLOBALS['pagenow'] = 'wp-login.php';
     225        $_GET['wp_lang']    = '###'; // Something sanitize_locale_name() strips away.
     226
     227        $this->assertSame( 'siteLocale', determine_locale() );
     228    }
     229
    214230    public function test_wp_login_cookie_not_on_login_page() {
    215231        add_filter(
Note: See TracChangeset for help on using the changeset viewer.