Fix encoding of Unicode keys greater than U+00FF (greater than U+FFFF handled by surrogate pairs)

This commit is contained in:
Jessica
2019-02-19 15:52:24 +09:00
parent a4212dcdce
commit 4ee74f7e6c
2 changed files with 5 additions and 3 deletions
+2
View File
@@ -566,6 +566,8 @@ export function attach(
if (key !== null) {
if (typeof key === 'number') {
// unreachable code?
// https://github.com/facebook/react/blob/master/packages/react/src/ReactElement.js#L187
encodedKey = new Uint8Array(1);
encodedKey[0] = key;
} else {
+3 -3
View File
@@ -51,7 +51,7 @@ export function getUID(): number {
return ++uidCounter;
}
export function utfDecodeString(array: Uint8Array): string {
export function utfDecodeString(array: Uint16Array): string {
let string = '';
const { length } = array;
for (let i = 0; i < length; i++) {
@@ -60,8 +60,8 @@ export function utfDecodeString(array: Uint8Array): string {
return string;
}
export function utfEncodeString(string: string): Uint8Array {
const array = new Uint8Array(string.length);
export function utfEncodeString(string: string): Uint16Array {
const array = new Uint16Array(string.length);
const { length } = string;
for (let i = 0; i < length; i++) {
array[i] = string.charCodeAt(i);