瀏覽代碼

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.
master
Saúl Ibarra Corretgé 5 年之前
父節點
當前提交
191e530071

+ 6
- 0
package-lock.json 查看文件

@@ -17595,6 +17595,12 @@
17595 17595
       "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
17596 17596
       "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
17597 17597
     },
17598
+    "unorm": {
17599
+      "version": "1.6.0",
17600
+      "resolved": "https://registry.npmjs.org/unorm/-/unorm-1.6.0.tgz",
17601
+      "integrity": "sha512-b2/KCUlYZUeA7JFUuRJZPUtr4gZvBh7tavtv4fvk4+KV9pfGiR6CQAQAWl49ZpR3ts2dk4FYkP7EIgDJoiOLDA==",
17602
+      "dev": true
17603
+    },
17598 17604
     "unpipe": {
17599 17605
       "version": "1.0.0",
17600 17606
       "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",

+ 1
- 0
package.json 查看文件

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

+ 14
- 0
react/features/base/util/strings.native.js 查看文件

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

+ 11
- 0
react/features/base/util/strings.web.js 查看文件

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

+ 4
- 2
react/features/base/util/uri.js 查看文件

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

Loading…
取消
儲存