Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f1733c

Browse filesBrowse files
gagernFishrock123
authored andcommitted
test: add more UTF-8 StringDecoder tests
PR-URL: #7310 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
1 parent 962ac37 commit 8f1733c
Copy full SHA for 8f1733c

File tree

Expand file treeCollapse file tree

1 file changed

+30
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+30
-0
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-string-decoder.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-string-decoder.js
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ test(
2828
'\u02e4\u0064\u12e4\u0030\u3045'
2929
);
3030

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+
3155
// UCS-2
3256
test('ucs2', Buffer.from('ababc', 'ucs2'), 'ababc');
3357

@@ -58,6 +82,11 @@ decoder = new StringDecoder('utf8');
5882
assert.strictEqual(decoder.write(Buffer.from('EFBFBDE2', 'hex')), '\ufffd');
5983
assert.strictEqual(decoder.end(), '\ufffd');
6084

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+
6190

6291
// Additional UTF-16LE surrogate pair tests
6392
decoder = new StringDecoder('utf16le');
@@ -93,6 +122,7 @@ function test(encoding, input, expected, singleSequence) {
93122
sequence.forEach(function(write) {
94123
output += decoder.write(input.slice(write[0], write[1]));
95124
});
125+
output += decoder.end();
96126
process.stdout.write('.');
97127
if (output !== expected) {
98128
var message =

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.