Skip to content

Commit 5c3064c

Browse files
committed
test: iso-2022-jp fatal stream
1 parent cb9e276 commit 5c3064c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tests/encoding/mistakes.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,23 +712,34 @@ describe('Common implementation mistakes', () => {
712712
})
713713
}
714714

715-
// Bun is incorrect
716715
test('iso-2022-jp', (t) => {
717716
// This is the only decoder which does not clear internal state before throwing in stream mode (non-EOF throws)
718717
// So the internal state of this decoder can legitimately persist after an error was thrown
718+
719+
// Bun is incorrect
719720
{
720721
const d = new TextDecoder('iso-2022-jp', { fatal: true })
721722
t.assert.strictEqual(d.decode(Uint8Array.of(0x7e)), '\x7E')
722723
t.assert.throws(() => d.decode(u(0x1b, 0x28, 0x4a, 0xff), { stream: true })) // Switch to Roman, error
723724
t.assert.strictEqual(d.decode(Uint8Array.of(0x7e)), '\u203E')
724725
}
725726

727+
// Bun is incorrect
726728
{
727729
const d = new TextDecoder('iso-2022-jp', { fatal: true })
728730
t.assert.strictEqual(d.decode(Uint8Array.of(0x42)), 'B')
729731
t.assert.throws(() => d.decode(u(0x1b, 0x28, 0x49, 0xff), { stream: true })) // Switch to Katakana, error
730732
t.assert.strictEqual(d.decode(Uint8Array.of(0x42)), '\uFF82')
731733
}
734+
735+
// Pushback queue should be cleared though
736+
// Chrome and WebKit are wrong. Firefox is correct
737+
{
738+
const d = new TextDecoder('iso-2022-jp', { fatal: true })
739+
t.assert.strictEqual(d.decode(Uint8Array.of(0x42)), 'B')
740+
t.assert.throws(() => d.decode(u(0x1b, 0x21, 0x22), { stream: true })) // Invalid escape
741+
t.assert.strictEqual(d.decode(Uint8Array.of(0x42)), 'B')
742+
}
732743
})
733744

734745
// Firefox, Deno and Servo are wrong. Chrome and WebKit are correct

0 commit comments

Comments
 (0)