facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.09k stars 24.32k forks source link

string.normalize('NFKD') crashes on some characters (Android only) #37671

Closed robbeman closed 1 year ago

robbeman commented 1 year ago

Description

When calling 'some string with Ü'.normalize('NFKD') the JS engine will crash.

The error is not catchable with try{} catch, so very hard to debug.

// The string doing the thing
const string = 'REÜNIE';

// the normalize calls
console.log('normalize', string.normalize('NFC')); // works
console.log('normalize', string.normalize('NFD')); // works
console.log('normalize', string.normalize('NFKC')); // crash
console.log('normalize', string.normalize('NFKD')); // crash

React Native Version

0.71.8

Output of npx react-native info

System: OS: macOS 12.6 CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz Memory: 1.67 GB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v18.13.0/bin/yarn npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm Watchman: 2023.05.22.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.12.1 - /Users/robbeclerckx/.rvm/gems/ruby-2.7.6/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: API Levels: 23, 25, 26, 27, 28, 29, 30, 31, 33 Build Tools: 30.0.2, 30.0.3, 31.0.0, 33.0.0, 34.0.0 System Images: android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-31 | Google APIs Intel x86 Atom_64 Android NDK: Not Found IDEs: Android Studio: 2022.1 AI-221.6008.13.2211.9619390 Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 11.0.15 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: ^0.71.0 => 0.71.8 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

  1. Make a string containing some special character like Ü
  2. Call .normalize('NFKD') on that string.

Snack, code example, screenshot, or link to a repository

https://snack.expo.dev/xzdS9Sw4p

cortinico commented 1 year ago

@robbeman Are you on Hermes or JSC?

robbeman commented 1 year ago

@robbeman Are you on Hermes or JSC?

JSC, because Hermes seems to be incompatible with firebase (which is included in the project I am working on).

cortinico commented 1 year ago

Then there is not much we can do as we don't offer support for engine specific bugs for JSC. I'm unsure if this is a bug in the engine or not sadly. Could you provide a reproducer on a empty project with Hermes?

github-actions[bot] commented 1 year ago
:warning: Missing Reproducible Example
:information_source: It looks like your issue is missing a reproducible example. Please provide either:
robbeman commented 1 year ago

Okay, I checked the snack I added in the initial report and it is indeed running in JSC as well. (Not sure if it is even possible to use hermes in snack?)

Thank you for having a look anyway.

For future reference: I added a small polyfill for android in /index.js which seems to work.

// replace broken normalize('NFKD') on android
if (Platform.OS === 'android') {
  // delete before applying polyfill
  delete String.prototype.normalize;
  import('unorm');
}