[wp-trac] [WordPress Trac] #52695: Incorrect way to updateLocale in moment.js add_inline_script

WordPress Trac noreply at wordpress.org
Tue Mar 2 16:38:07 UTC 2021


#52695: Incorrect way to updateLocale in moment.js add_inline_script
--------------------------------+-----------------------------
 Reporter:  yoancutillas        |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  External Libraries  |    Version:  5.6.2
 Severity:  normal              |   Keywords:
  Focuses:                      |
--------------------------------+-----------------------------
 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**

 **1.1**
 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,
 )
 }}}


 **1.2**
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52695>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list