diff --git a/src/index.ts b/src/index.ts index 197413e..9a5cfba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -125,7 +125,7 @@ function getDecodedEntity( : parseInt(entity.substr(2)); decodeResult = - decodeCode >= 0x10ffff + decodeCode > 0x10ffff ? outOfBoundsChar : decodeCode > 65535 ? fromCodePoint(decodeCode) diff --git a/test/index.test.ts b/test/index.test.ts index 37d7311..963b432 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -179,6 +179,15 @@ describe('lib', () => { expect(decode(entity)).toEqual(value); } }); + it('should decode the maximum code point U+10FFFF instead of replacing it', () => { + const maxCodePoint = String.fromCodePoint(0x10ffff); + expect(decode('􏿿')).toEqual(maxCodePoint); + expect(decode('􏿿')).toEqual(maxCodePoint); + // round-trip: encode emits a reference that decode must read back + expect(decode(encode(maxCodePoint, {mode: 'nonAscii'}))).toEqual(maxCodePoint); + // code points past the Unicode range stay replaced + expect(decode('�')).toEqual(String.fromCharCode(65533)); + }); }); });