rxaviers / cldrjs

Simple CLDR traverser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Global state pollution bug

morwoen opened this issue · comments

What happened

At the Localisation & Globalisation team at my company, we've decided to release an internal "test" locale (we called it xx-XX) to provide pseudo localisation for all other teams across. Since this locale is fictional there is no CLDR data for it. Our approach was to take es-ES and alter the data so that it acts as the new xx-XX locale.

During the process we've missed the likelySubtags object, meaning there was a mismatch

"main": {
  "xx-XX": {...}
},
"supplemental": {
  "likelySubtags": {
    "und": "es",
    "es-ES": "es"
  }
}

The error

Passing this data into a Globalize.load() (which in turn calls CLDR.load()) causes no errors, however, instantiating a new instance new Globalize(locale) throws TypeError: Cannot read property '0' of undefined. Note that what locale is above doesn't matter. Locales with already loaded valid data can no longer be used.

We've traced the error to this file in this repo. The error is thrown on line 23. It looks like it stores the data in a global variable and never clears the state in case of an error.

Expected outcome

An error to be thrown only once and the data is ejected from the queue to allow the application to continue without a need to restart.

Impact

The service that observed the error is using Globalize in its backend. This means that after an internal user (xx-XX is only an internal locale, no end-user can request it) tested the new locale end-users using actual locales started seeing errors due to the recurring exception thrown for valid locales.

PS. We are happy to contribute a fix, we want to first get the opinion/proposition of the maintainers :)