2018-12-20 07:20:31 +01:00
|
|
|
'use strict';
|
|
|
|
// From: https://github.com/w3c/web-platform-tests/blob/master/encoding/api-invalid-label.html
|
|
|
|
// With the twist that we specifically test for Node.js error codes
|
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
2018-12-20 07:20:31 +01:00
|
|
|
|
|
|
|
[
|
|
|
|
'utf-8',
|
|
|
|
'unicode-1-1-utf-8',
|
2023-09-23 14:20:39 +02:00
|
|
|
'unicode11utf8',
|
|
|
|
'unicode20utf8',
|
|
|
|
'x-unicode20utf8',
|
2018-12-20 07:20:31 +01:00
|
|
|
'utf8',
|
2023-09-23 14:20:39 +02:00
|
|
|
'unicodefffe',
|
2018-12-20 07:20:31 +01:00
|
|
|
'utf-16be',
|
2023-09-23 14:20:39 +02:00
|
|
|
'csunicode',
|
|
|
|
'iso-10646-ucs-2',
|
|
|
|
'ucs-2',
|
|
|
|
'unicode',
|
|
|
|
'unicodefeff',
|
2018-12-20 07:20:31 +01:00
|
|
|
'utf-16le',
|
2021-03-26 16:51:08 +01:00
|
|
|
'utf-16',
|
2018-12-20 07:20:31 +01:00
|
|
|
].forEach((i) => {
|
|
|
|
['\u0000', '\u000b', '\u00a0', '\u2028', '\u2029'].forEach((ws) => {
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(
|
2018-12-20 07:20:31 +01:00
|
|
|
() => new TextDecoder(`${ws}${i}`),
|
|
|
|
{
|
|
|
|
code: 'ERR_ENCODING_NOT_SUPPORTED',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'RangeError'
|
2018-12-20 07:20:31 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(
|
2018-12-20 07:20:31 +01:00
|
|
|
() => new TextDecoder(`${i}${ws}`),
|
|
|
|
{
|
|
|
|
code: 'ERR_ENCODING_NOT_SUPPORTED',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'RangeError'
|
2018-12-20 07:20:31 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(
|
2018-12-20 07:20:31 +01:00
|
|
|
() => new TextDecoder(`${ws}${i}${ws}`),
|
|
|
|
{
|
|
|
|
code: 'ERR_ENCODING_NOT_SUPPORTED',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'RangeError'
|
2018-12-20 07:20:31 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|