Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getLocales crashes due to unsupported locales #25694

Closed
michaelpomogajko opened this issue Dec 1, 2023 · 1 comment · Fixed by #28902
Closed

getLocales crashes due to unsupported locales #25694

michaelpomogajko opened this issue Dec 1, 2023 · 1 comment · Fixed by #28902
Labels
Localization needs review Issue is ready to be reviewed by a maintainer

Comments

@michaelpomogajko
Copy link

michaelpomogajko commented Dec 1, 2023

Minimal reproducible example

https://snack.expo.dev/3e1UB5xwZ

Summary

Call to function 'ExpoLocalization.getLocales' has been rejected.
→ Caused by: java.lang.IllegalArgumentException: Unsupported ISO 3166 country: pl_SP

Also saw the same issue with following country code es_419

Snack can't reproduce the issue due to not able to change locales of device

Environment

Environment
expo-env-info 1.0.5 environment info:
System:
OS: macOS 13.2.1
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/Library/Caches/fnm_multishells/90040_1701414843416/bin/node
Yarn: 1.22.21 - ~/Library/Caches/fnm_multishells/90040_1701414843416/bin/yarn
npm: 10.2.4 - ~/Library/Caches/fnm_multishells/90040_1701414843416/bin/npm
Watchman: 2023.11.20.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.14.2 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
IDEs:
Android Studio: 2022.3 AI-223.8836.35.2231.11090377
Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
npmPackages:
expo: ~48.0.21 => 48.0.21
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.71.14 => 0.71.14
react-native-web: ~0.18.12 => 0.18.12
npmGlobalPackages:
eas-cli: 5.9.1
Expo Workflow: bare

@michaelpomogajko michaelpomogajko added the needs validation Issue needs to be validated label Dec 1, 2023
@expo-bot expo-bot added needs review Issue is ready to be reviewed by a maintainer and removed needs validation Issue needs to be validated labels Dec 1, 2023
@GPHemsley
Copy link

This is occurring because getLocales() is passing the results of getNavigatorLocales() directly into Intl.Locale() and not guarding against the exceptions that could be thrown as a result.

getLocales(): Locale[] {
const locales = getNavigatorLocales();
return locales?.map((languageTag) => {
// TextInfo is an experimental API that is not available in all browsers.
// We might want to consider using a locale lookup table instead.
const locale =
typeof Intl !== 'undefined'
? (new Intl.Locale(languageTag) as unknown as ExtendedLocale)
: { region: null, textInfo: null, language: null };

navigator.languages can contain any valid BCP 47 language tag. However, Intl depends on Unicode's definition of a locale identifier which explicitly excludes a subset of valid BCP 47 language tags.

This means, for example, having "en-GB-oed" in your Accept-Language header eventually results in a RangeError being thrown that, uncaught, could make an entire app unusable.

So, in addition to failing on legitimately invalid language tags (as with the given pl-SP), it will also fail on valid language tags that are not supported by Intl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Localization needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
4 participants