Skip to content

Commit f605566

Browse files
authored
fix(i18n): prevent infinite loop when fetching bundles (#1333)
Prevent the possibility of infinite loop, if localeId is null, undefined, etc.: FIXES: #1318
1 parent d9d3e57 commit f605566

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/base/src/locale/nextFallbackLocale.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* Calculates the next fallback locale for the given locale.
33
*
44
* @param {string} locale Locale string in Java format (underscores) or null
5-
* @returns {string|null} Next fallback Locale or null if there is no more fallback
5+
* @returns {string} Next fallback Locale or "en" if no fallbacks found.
66
*/
77
const nextFallbackLocale = locale => {
88
if (!locale) {
9-
return null;
9+
return "en";
1010
}
1111

1212
if (locale === "zh_HK") {

packages/base/src/locale/normalizeLocale.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ const M_ISO639_NEW_TO_OLD = {
1212
/**
1313
* Normalizes the given locale in BCP-47 syntax.
1414
* @param {string} locale locale to normalize
15-
* @returns {string} Normalized locale or undefined if the locale can't be normalized
15+
* @returns {string} Normalized locale, "undefined" if the locale can't be normalized or "en" if no locale provided.
1616
*/
1717
const normalizeLocale = locale => {
1818
let m;
1919

20+
if (!locale) {
21+
return "en";
22+
}
23+
2024
if (typeof locale === "string" && (m = localeRegEX.exec(locale.replace(/_/g, "-")))) {/* eslint-disable-line */
2125
let language = m[1].toLowerCase();
2226
let region = m[3] ? m[3].toUpperCase() : undefined;

0 commit comments

Comments
 (0)