Skip to content

Commit 94fd779

Browse files
author
pluris
committed
lib: update encoding sets in WHATWG API
1 parent b0edb28 commit 94fd779

4 files changed

+52
-6
lines changed

lib/internal/encoding.js

+17
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ const empty = new Uint8Array(0);
7676

7777
const encodings = new SafeMap([
7878
['unicode-1-1-utf-8', 'utf-8'],
79+
['unicode-11utf8', 'utf-8'],
80+
['unicode-20utf8', 'utf-8'],
7981
['utf8', 'utf-8'],
8082
['utf-8', 'utf-8'],
83+
['x-unicode20utf8', 'utf-8'],
8184
['866', 'ibm866'],
8285
['cp866', 'ibm866'],
8386
['csibm866', 'ibm866'],
@@ -176,6 +179,7 @@ const encodings = new SafeMap([
176179
['iso885915', 'iso-8859-15'],
177180
['iso_8859-15', 'iso-8859-15'],
178181
['l9', 'iso-8859-15'],
182+
['iso-8859-16', 'iso-8859-16'],
179183
['cskoi8r', 'koi8-r'],
180184
['koi', 'koi8-r'],
181185
['koi8', 'koi8-r'],
@@ -283,9 +287,22 @@ const encodings = new SafeMap([
283287
['ksc5601', 'euc-kr'],
284288
['ksc_5601', 'euc-kr'],
285289
['windows-949', 'euc-kr'],
290+
['csiso2022kr', 'replacement'],
291+
['hz-gb-2312', 'replacement'],
292+
['iso-2022-cn', 'replacement'],
293+
['iso-2022-cn-ext', 'replacement'],
294+
['iso-2022-kr', 'replacement'],
295+
['replacement', 'replacement'],
296+
['unicodefffe', 'utf-16be'],
286297
['utf-16be', 'utf-16be'],
298+
['csunicode', 'utf-16le'],
299+
['iso-10646-ucs-2', 'utf-16le'],
300+
['ucs-2', 'utf-16le'],
301+
['unicode', 'utf-16le'],
302+
['unicodefeff', 'utf-16le'],
287303
['utf-16le', 'utf-16le'],
288304
['utf-16', 'utf-16le'],
305+
['x-user-defined', 'x-user-defined'],
289306
]);
290307

291308
// Unfortunately, String.prototype.trim also removes non-ascii whitespace,

test/parallel/test-whatwg-encoding-custom-internals.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,20 @@ const { getEncodingFromLabel } = require('internal/encoding');
1313
const mappings = {
1414
'utf-8': [
1515
'unicode-1-1-utf-8',
16+
'unicode-11utf8',
17+
'unicode-20utf8',
1618
'utf8',
19+
'x-unicode20utf8',
20+
],
21+
'utf-16be': [
22+
'unicodefffe',
1723
],
18-
'utf-16be': [],
1924
'utf-16le': [
25+
'csunicode',
26+
'iso-10646-ucs-2',
27+
'ucs-2',
28+
'unicode',
29+
'unicodefeff',
2030
'utf-16',
2131
],
2232
'ibm866': [
@@ -258,7 +268,15 @@ const { getEncodingFromLabel } = require('internal/encoding');
258268
'ksc5601',
259269
'ksc_5601',
260270
'windows-949',
261-
]
271+
],
272+
'replacement': [
273+
'csiso2022kr',
274+
'hz-gb-2312',
275+
'iso-2022-cn',
276+
'iso-2022-cn-ext',
277+
'iso-2022-kr',
278+
],
279+
'x-user-defined': []
262280
};
263281
Object.entries(mappings).forEach((i) => {
264282
const enc = i[0];

test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js

+9
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ const assert = require('assert');
88
[
99
'utf-8',
1010
'unicode-1-1-utf-8',
11+
'unicode-11utf8',
12+
'unicode-20utf8',
13+
'x-unicode20utf8',
1114
'utf8',
15+
'unicodefffe',
1216
'utf-16be',
17+
'csunicode',
18+
'iso-10646-ucs-2',
19+
'ucs-2',
20+
'unicode',
21+
'unicodefeff',
1322
'utf-16le',
1423
'utf-16',
1524
].forEach((i) => {

test/parallel/test-whatwg-encoding-custom-textdecoder.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ const util = require('util');
1313
const buf = Buffer.from([0xef, 0xbb, 0xbf, 0x74, 0x65,
1414
0x73, 0x74, 0xe2, 0x82, 0xac]);
1515

16+
const encoding_sets = ['unicode-1-1-utf-8', 'unicode-11utf8', 'unicode-20utf8',
17+
'utf8', 'utf-8', 'x-unicode20utf8'];
1618
// Make Sure TextDecoder exist
1719
assert(TextDecoder);
1820

1921
// Test TextDecoder, UTF-8, fatal: false, ignoreBOM: false
2022
{
21-
['unicode-1-1-utf-8', 'utf8', 'utf-8'].forEach((i) => {
23+
encoding_sets.forEach((i) => {
2224
const dec = new TextDecoder(i);
2325
assert.strictEqual(dec.encoding, 'utf-8');
2426
const res = dec.decode(buf);
2527
assert.strictEqual(res, 'test€');
2628
});
2729

28-
['unicode-1-1-utf-8', 'utf8', 'utf-8'].forEach((i) => {
30+
encoding_sets.forEach((i) => {
2931
const dec = new TextDecoder(i);
3032
let res = '';
3133
res += dec.decode(buf.slice(0, 8), { stream: true });
@@ -36,13 +38,13 @@ assert(TextDecoder);
3638

3739
// Test TextDecoder, UTF-8, fatal: false, ignoreBOM: true
3840
{
39-
['unicode-1-1-utf-8', 'utf8', 'utf-8'].forEach((i) => {
41+
encoding_sets.forEach((i) => {
4042
const dec = new TextDecoder(i, { ignoreBOM: true });
4143
const res = dec.decode(buf);
4244
assert.strictEqual(res, '\ufefftest€');
4345
});
4446

45-
['unicode-1-1-utf-8', 'utf8', 'utf-8'].forEach((i) => {
47+
encoding_sets.forEach((i) => {
4648
const dec = new TextDecoder(i, { ignoreBOM: true });
4749
let res = '';
4850
res += dec.decode(buf.slice(0, 8), { stream: true });

0 commit comments

Comments
 (0)