uri: avoid using String.prototype.normalize

It crashes on Android. Well, on the JSC version React Native uses on Android.

While we could use this fallback only on Android, we have decided to use it
on all mobile platforms for consistency.
This commit is contained in:
Saúl Ibarra Corretgé 2019-11-06 14:42:49 +01:00 committed by Saúl Ibarra Corretgé
parent ae30d39b4d
commit 191e530071
5 changed files with 36 additions and 2 deletions

6
package-lock.json generated
View File

@ -17595,6 +17595,12 @@
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
}, },
"unorm": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/unorm/-/unorm-1.6.0.tgz",
"integrity": "sha512-b2/KCUlYZUeA7JFUuRJZPUtr4gZvBh7tavtv4fvk4+KV9pfGiR6CQAQAWl49ZpR3ts2dk4FYkP7EIgDJoiOLDA==",
"dev": true
},
"unpipe": { "unpipe": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",

View File

@ -126,6 +126,7 @@
"precommit-hook": "3.0.0", "precommit-hook": "3.0.0",
"string-replace-loader": "2.1.1", "string-replace-loader": "2.1.1",
"style-loader": "0.19.0", "style-loader": "0.19.0",
"unorm": "1.6.0",
"webpack": "4.27.1", "webpack": "4.27.1",
"webpack-bundle-analyzer": "3.4.1", "webpack-bundle-analyzer": "3.4.1",
"webpack-cli": "3.1.2", "webpack-cli": "3.1.2",

View File

@ -0,0 +1,14 @@
// @flow
import * as unorm from 'unorm';
/**
* Applies NFKC normalization to the given text.
* NOTE: Here we use the unorm package because the JSC version in React Native for Android crashes.
*
* @param {string} text - The text that needs to be normalized.
* @returns {string} - The normalized text.
*/
export function normalizeNFKC(text: string) {
return unorm.nfkc(text);
}

View File

@ -0,0 +1,11 @@
// @flow
/**
* Applies NFKC normalization to the given text.
*
* @param {string} text - The text that needs to be normalized.
* @returns {string} - The normalized text.
*/
export function normalizeNFKC(text: string) {
return text.normalize('NFKC');
}

View File

@ -1,5 +1,7 @@
// @flow // @flow
import { normalizeNFKC } from './strings';
/** /**
* The app linking scheme. * The app linking scheme.
* TODO: This should be read from the manifest files later. * TODO: This should be read from the manifest files later.
@ -120,8 +122,8 @@ export function getBackendSafeRoomName(room: ?string): ?string {
// But in this case we're fine goin on... // But in this case we're fine goin on...
} }
// Normalize the character set // Normalize the character set.
room = room.normalize('NFKC'); room = normalizeNFKC(room);
// Only decoded and normalized strings can be lowercased properly. // Only decoded and normalized strings can be lowercased properly.
room = room.toLowerCase(); room = room.toLowerCase();