Skip to content

Commit f665f0d

Browse files
committed
Checking for buffer in inputs prior to decoding
1 parent 16e5206 commit f665f0d

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

lib/TextDecoder-impl.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ exports.implementation = class TextDecoderImpl {
3030
// TODO: Implement stream support
3131
}
3232
try {
33-
// TODO: Implement ignoreBOM support
34-
return decode(Buffer.from(input), this._encoding, this._ignoreBOM);
33+
return decode(input, this._encoding, this._ignoreBOM);
3534
} catch (exception) {
3635
if (this._errorMode === "fatal") {
3736
throw new TypeError(exception);

lib/whatwg-encoding.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,27 @@ exports.labelToName = label => {
1313
};
1414

1515
// https://encoding.spec.whatwg.org/#decode
16-
exports.decode = (buffer, fallbackEncodingName, ignoreBOM) => {
16+
exports.decode = (input, fallbackEncodingName, ignoreBOM) => {
1717
let encoding = fallbackEncodingName;
1818
if (!exports.isSupported(encoding)) {
1919
throw new RangeError(`"${encoding}" is not a supported encoding name`);
2020
}
2121

22-
const bomEncoding = exports.getBOMEncoding(buffer);
23-
if (!ignoreBOM && bomEncoding !== null) {
22+
const bomEncoding = exports.getBOMEncoding(input);
23+
if (bomEncoding !== null) {
2424
encoding = bomEncoding;
2525
}
2626

2727
// iconv-lite will strip BOMs for us, so no need to do the stuff the spec does
28+
2829
const decodeOptions = {
2930
stripBOM: !ignoreBOM
3031
};
3132

32-
return iconvLite.decode(buffer, encoding, decodeOptions);
33+
if (input.buffer !== undefined)
34+
return iconvLite.decode(input, encoding, decodeOptions);
35+
else
36+
return iconvLite.decode(Buffer.from(input), encoding, decodeOptions);
3337
};
3438

3539

scripts/get-latest-platform-tests.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,48 @@ const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests");
3030

3131
for (const file of [
3232
"api-basics.any.js",
33+
34+
// Missing testharness 'setup' function
3335
// "api-invalid-label.any.js",
36+
3437
"api-replacement-encodings.any.js",
3538
"api-surrogates-utf8.any.js",
39+
40+
// Missing testharness 'createBuffer' function
3641
// "encodeInto.any.js",
42+
43+
// Missing testharness 'decode_test' function
3744
// "replacement-encodings.any.js",
45+
3846
"textdecoder-byte-order-marks.any.js",
47+
48+
// Missing testharness 'createBuffer' function
3949
// "textdecoder-copy.any.js",
50+
51+
// Package 'iconv-lite' does not support 'x-mac-cyrillic'
4052
// "textdecoder-fatal-single-byte.any.js",
53+
54+
// Stream support not implemented
4155
// "textdecoder-fatal-streaming.any.js",
56+
4257
// "textdecoder-fatal.any.js",
58+
4359
"textdecoder-ignorebom.any.js",
60+
61+
// Infinite looping
4462
// "textdecoder-labels.any.js",
63+
64+
// Stream support not implemented
4565
// "textdecoder-streaming.any.js",
66+
4667
// "textdecoder-utf16-surrogates.any.js"
68+
69+
// Package 'iconv-lite' does not support 'x-mac-cyrillic', 'ISO-8859-8-I', 'ISO-2022-JP', 'x-user-defined'
4770
// "textencoder-constructor-non-utf.any.js",
48-
// "textencoder-utf16-surrogates.any.js",
71+
72+
"textencoder-utf16-surrogates.any.js",
73+
74+
// Missing testharness 'decode_test' function
4975
// "unsupported-encodings.any.js"
5076
]) {
5177
pipeline(

0 commit comments

Comments
 (0)