Fix encoding of Unicode keys greater than U+00FF (greater than U+FFFF handled by surrogate pairs)
Jessica committed
Feb 19, 2019 at 15:52 UTC
4ee74f7e6c8b918bec5414aa6289c3009864c136
2 files changed
+5
-3
src/backend/renderer.js
+2
@@ -566,6 +566,8 @@ export function attach(
566
567
if (key !== null) {
568
if (typeof key === 'number') {
569
+ // unreachable code?
570
+ // https://github.com/facebook/react/blob/master/packages/react/src/ReactElement.js#L187
571
encodedKey = new Uint8Array(1);
572
encodedKey[0] = key;
573
} else {
src/utils.js
+3
-3
@@ -51,7 +51,7 @@ export function getUID(): number {
51
return ++uidCounter;
52
}
53
54
-export function utfDecodeString(array: Uint8Array): string {
54
+export function utfDecodeString(array: Uint16Array): string {
55
let string = '';
56
const { length } = array;
57
for (let i = 0; i < length; i++) {
@@ -60,8 +60,8 @@ export function utfDecodeString(array: Uint8Array): string {
60
return string;
61
}
62
63
-export function utfEncodeString(string: string): Uint8Array {
64
- const array = new Uint8Array(string.length);
63
+export function utfEncodeString(string: string): Uint16Array {
64
+ const array = new Uint16Array(string.length);
65
const { length } = string;
66
for (let i = 0; i < length; i++) {
67
array[i] = string.charCodeAt(i);