Make WordPress Core

Opened 8 months ago

#52695 new defect (bug)

Incorrect way to updateLocale in moment.js add_inline_script

Reported by: yoancutillas Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.6.2
Component: External Libraries Keywords:
Focuses: Cc:


In [wp-includes/script-loader.php L146](https://build.trac.wordpress.org/browser/branches/5.7/wp-includes/script-loader.php#L146)

moment.updateLocale( '%s', %s );

WP updates the locale
1. with incomplete data
2. regardless of the existing data

The plugins / themes calling for the removed data expect a String, and they will get an undefined, triggering an Uncaught TypeError for any further process.

This is not too visible yet because of the bug #51142.
But when it will be fixed, a lot of scripts will be affected.

1. Incomplete data

WP currently updates 'longDateFormat' with null parameters. Parameters values should not be null. I suggest to use the 'en_US' values as default.

The parameters should not be null: 'LTS', 'L', 'LLLL'

'longDateFormat' => array(
	'LT'   => get_option( 'time_format', __( 'g:i a', 'default' ) ),
	'LTS'  => null,
	'L'    => null,
	'LL'   => get_option( 'date_format', __( 'F j, Y', 'default' ) ),
	'LLL'  => __( 'F j, Y g:i a', 'default' ),
	'LLLL' => null,

WP currently updates 'week' with 1 parameter instead of 2 (https://momentjs.com/docs/#/customization/dow-doy/).

Missing parameter: 'doy'

'week' => array(
	'dow' => (int) get_option( 'start_of_week', 0 ),

2. Existing data

Before calling updateLocale, WP should check if the locale data exists (with moment.localeData( 'en' ) - [docs](https://momentjs.com/docs/#/i18n/locale-data/)).

I suggest to replace only the missing data, and keep the existing one as is.

Change History (0)

Note: See TracTickets for help on using tickets.