|
28 | 28 | '\u02e4\u0064\u12e4\u0030\u3045'
|
29 | 29 | );
|
30 | 30 |
|
| 31 | +// Some invalid input, known to have caused trouble with chunking |
| 32 | +// in https://github.com/nodejs/node/pull/7310#issuecomment-226445923 |
| 33 | +// 00: |00000000 ASCII |
| 34 | +// 41: |01000001 ASCII |
| 35 | +// B8: 10|111000 continuation |
| 36 | +// CC: 110|01100 two-byte head |
| 37 | +// E2: 1110|0010 three-byte head |
| 38 | +// F0: 11110|000 four-byte head |
| 39 | +// F1: 11110|001'another four-byte head |
| 40 | +// FB: 111110|11 "five-byte head", not UTF-8 |
| 41 | +test('utf-8', Buffer.from('C9B5A941', 'hex'), '\u0275\ufffdA'); |
| 42 | +test('utf-8', Buffer.from('E2', 'hex'), '\ufffd'); |
| 43 | +test('utf-8', Buffer.from('E241', 'hex'), '\ufffdA'); |
| 44 | +test('utf-8', Buffer.from('CCCCB8', 'hex'), '\ufffd\u0338'); |
| 45 | +test('utf-8', Buffer.from('F0B841', 'hex'), '\ufffd\ufffdA'); |
| 46 | +test('utf-8', Buffer.from('F1CCB8', 'hex'), '\ufffd\u0338'); |
| 47 | +test('utf-8', Buffer.from('F0FB00', 'hex'), '\ufffd\ufffd\0'); |
| 48 | +test('utf-8', Buffer.from('CCE2B8B8', 'hex'), '\ufffd\u2e38'); |
| 49 | +test('utf-8', Buffer.from('E2B8CCB8', 'hex'), '\ufffd\ufffd\u0338'); |
| 50 | +test('utf-8', Buffer.from('E2FBCC01', 'hex'), '\ufffd\ufffd\ufffd\u0001'); |
| 51 | +test('utf-8', Buffer.from('EDA0B5EDB08D', 'hex'), // CESU-8 of U+1D40D |
| 52 | + '\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd'); |
| 53 | +test('utf-8', Buffer.from('CCB8CDB9', 'hex'), '\u0338\u0379'); |
| 54 | + |
31 | 55 | // UCS-2
|
32 | 56 | test('ucs2', Buffer.from('ababc', 'ucs2'), 'ababc');
|
33 | 57 |
|
@@ -58,6 +82,11 @@ decoder = new StringDecoder('utf8');
|
58 | 82 | assert.strictEqual(decoder.write(Buffer.from('EFBFBDE2', 'hex')), '\ufffd');
|
59 | 83 | assert.strictEqual(decoder.end(), '\ufffd');
|
60 | 84 |
|
| 85 | +decoder = new StringDecoder('utf8'); |
| 86 | +assert.strictEqual(decoder.write(Buffer.from('F1', 'hex')), ''); |
| 87 | +assert.strictEqual(decoder.write(Buffer.from('41F2', 'hex')), '\ufffdA'); |
| 88 | +assert.strictEqual(decoder.end(), '\ufffd'); |
| 89 | + |
61 | 90 |
|
62 | 91 | // Additional UTF-16LE surrogate pair tests
|
63 | 92 | decoder = new StringDecoder('utf16le');
|
@@ -93,6 +122,7 @@ function test(encoding, input, expected, singleSequence) {
|
93 | 122 | sequence.forEach(function(write) {
|
94 | 123 | output += decoder.write(input.slice(write[0], write[1]));
|
95 | 124 | });
|
| 125 | + output += decoder.end(); |
96 | 126 | process.stdout.write('.');
|
97 | 127 | if (output !== expected) {
|
98 | 128 | var message =
|
|
0 commit comments