Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:WordPress/wordpress-develop into 6…
Browse files Browse the repository at this point in the history
….4/about-page
  • Loading branch information
aaronjorbin committed Oct 17, 2023
2 parents ad76938 + c626e63 commit 50df03c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/wp-admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,23 @@
$_POST['gmt_offset'] = $_POST['timezone_string'];
$_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] );
$_POST['timezone_string'] = '';
} elseif ( isset( $_POST['timezone_string'] ) && ! in_array( $_POST['timezone_string'], timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) ) {
// Reset to the current value.
$current_timezone_string = get_option( 'timezone_string' );

if ( ! empty( $current_timezone_string ) ) {
$_POST['timezone_string'] = $current_timezone_string;
} else {
$_POST['gmt_offset'] = get_option( 'gmt_offset' );
$_POST['timezone_string'] = '';
}

add_settings_error(
'general',
'settings_updated',
__( 'The timezone you have entered is not valid. Please select a valid timezone.' ),
'error'
);
}

// Handle translation installation.
Expand Down
28 changes: 28 additions & 0 deletions tests/e2e/specs/general-settings-invalid-timezone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

test.describe( 'Settings -> General', () => {
const invalidTimezones = [ '', '0', 'Barry/Gary' ];

for ( const invalidTimezone of invalidTimezones ) {
test( `Does not allow saving an invalid timezone string with "${invalidTimezone}"`, async ( { admin, page } ) => {
await admin.visitAdminPage( '/options-general.php' );

// Set the timezone to a valid value.
await page.locator( '#timezone_string' ).evaluate( timezone => timezone.value = 'Europe/Lisbon' );

// Save changes.
await page.locator( '#submit' ).click();

// Set the timezone to an invalid value.
await page.locator( '#timezone_string' ).evaluate( ( timezone, invalidTimezone ) => {
timezone.options[0].value = invalidTimezone;
timezone.value = invalidTimezone;
}, invalidTimezone );

// Save changes.
await page.locator( '#submit' ).click();

await expect( page.locator( '#timezone_string' ) ).toHaveValue( 'Europe/Lisbon' );
} );
}
} );

0 comments on commit 50df03c

Please sign in to comment.