Skip to content

Commit

Permalink
fix(i18n): prevent infinite loop when fetching bundles (#1333)
Browse files Browse the repository at this point in the history
Prevent the possibility of infinite loop, if localeId is null, undefined, etc.:

FIXES: #1318
  • Loading branch information
ilhan007 committed Mar 23, 2020
1 parent d9d3e57 commit f605566
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/base/src/locale/nextFallbackLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Calculates the next fallback locale for the given locale.
*
* @param {string} locale Locale string in Java format (underscores) or null
* @returns {string|null} Next fallback Locale or null if there is no more fallback
* @returns {string} Next fallback Locale or "en" if no fallbacks found.
*/
const nextFallbackLocale = locale => {
if (!locale) {
return null;
return "en";
}

if (locale === "zh_HK") {
Expand Down
6 changes: 5 additions & 1 deletion packages/base/src/locale/normalizeLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ const M_ISO639_NEW_TO_OLD = {
/**
* Normalizes the given locale in BCP-47 syntax.
* @param {string} locale locale to normalize
* @returns {string} Normalized locale or undefined if the locale can't be normalized
* @returns {string} Normalized locale, "undefined" if the locale can't be normalized or "en" if no locale provided.
*/
const normalizeLocale = locale => {
let m;

if (!locale) {
return "en";
}

if (typeof locale === "string" && (m = localeRegEX.exec(locale.replace(/_/g, "-")))) {/* eslint-disable-line */
let language = m[1].toLowerCase();
let region = m[3] ? m[3].toUpperCase() : undefined;
Expand Down

0 comments on commit f605566

Please sign in to comment.