Skip to content

Commit 080188c

Browse files
authored
Merge pull request #2504 from jerch/fix_2495
fix typo in TextDecoder
2 parents 276463e + 30d3d46 commit 080188c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/common/input/TextDecoder.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { assert } from 'chai';
77
import { StringToUtf32, stringFromCodePoint, Utf8ToUtf32, utf32ToString } from 'common/input/TextDecoder';
88
import { encode } from 'utf8';
99

10+
1011
// convert UTF32 codepoints to string
1112
function toString(data: Uint32Array, length: number): string {
1213
if ((String as any).fromCodePoint) {
@@ -214,6 +215,16 @@ describe('text encodings', () => {
214215
}
215216
assert(decoded, 'Ä€𝄞Ö𝄞€Ü𝄞€');
216217
});
218+
it('test break after 3 bytes - issue #2495', () => {
219+
const decoder = new Utf8ToUtf32();
220+
const target = new Uint32Array(5);
221+
const utf8Data = fromByteString('\xf0\xa0\x9c\x8e');
222+
let written = decoder.decode(utf8Data.slice(0, 3), target);
223+
assert.equal(written, 0);
224+
written = decoder.decode(utf8Data.slice(3), target);
225+
assert.equal(written, 1);
226+
assert(toString(target, written), '𠜎');
227+
});
217228
});
218229
});
219230
});

src/common/input/TextDecoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class Utf8ToUtf32 {
194194
target[size++] = cp;
195195
}
196196
} else {
197-
if (codepoint < 0x010000 || codepoint > 0x10FFFF) {
197+
if (cp < 0x010000 || cp > 0x10FFFF) {
198198
// illegal codepoint
199199
} else {
200200
target[size++] = cp;

0 commit comments

Comments
 (0)