Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,23 @@ const encodings = new SafeMap([
['cp1251', 'windows-1251'],
['windows-1251', 'windows-1251'],
['x-cp1251', 'windows-1251'],
['ansi_x3.4-1968', 'windows-1252'],
['ascii', 'windows-1252'],
['cp1252', 'windows-1252'],
['cp819', 'windows-1252'],
['csisolatin1', 'windows-1252'],
['ibm819', 'windows-1252'],
['iso-8859-1', 'windows-1252'],
['iso-ir-100', 'windows-1252'],
['iso8859-1', 'windows-1252'],
['iso88591', 'windows-1252'],
['iso_8859-1', 'windows-1252'],
['iso_8859-1:1987', 'windows-1252'],
['l1', 'windows-1252'],
['latin1', 'windows-1252'],
['us-ascii', 'windows-1252'],
['ansi_x3.4-1968', 'iso-8859-1'],
['ascii', 'iso-8859-1'],
['cp819', 'iso-8859-1'],
['csisolatin1', 'iso-8859-1'],
['ibm819', 'iso-8859-1'],
['iso-8859-1', 'iso-8859-1'],
['iso-ir-100', 'iso-8859-1'],
['iso8859-1', 'iso-8859-1'],
['iso88591', 'iso-8859-1'],
['iso_8859-1', 'iso-8859-1'],
['iso_8859-1:1987', 'iso-8859-1'],
['l1', 'iso-8859-1'],
['latin1', 'iso-8859-1'],
['us-ascii', 'iso-8859-1'],
['windows-1252', 'windows-1252'],
['x-cp1252', 'windows-1252'],
['cp1252', 'windows-1252'],
['cp1253', 'windows-1253'],
['windows-1253', 'windows-1253'],
['x-cp1253', 'windows-1253'],
Expand Down Expand Up @@ -421,7 +421,7 @@ function makeTextDecoderICU() {
this[kFatal] = Boolean(options?.fatal);
// Only support fast path for UTF-8.
this[kUTF8FastPath] = enc === 'utf-8';
this[kLatin1FastPath] = enc === 'windows-1252';
this[kLatin1FastPath] = enc === 'iso-8859-1';
this[kHandle] = undefined;

if (!this[kUTF8FastPath] && !this[kLatin1FastPath]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const labelToName = {
'unicode-1-1-utf-8': 'utf-8',
'iso-8859-2': 'iso-8859-2',
'ascii': 'windows-1252',
'ascii': 'iso-8859-1',
'utf-16': 'utf-16le'
};

Expand Down
30 changes: 16 additions & 14 deletions test/parallel/test-whatwg-encoding-custom-internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ const { getEncodingFromLabel } = require('internal/encoding');
'cp866',
'csibm866',
],
'iso-8859-1': [
'ansi_x3.4-1968',
'ascii',
'cp819',
'csisolatin1',
'ibm819',
'iso-ir-100',
'iso8859-1',
'iso88591',
'iso_8859-1',
'iso_8859-1:1987',
'l1',
'latin1',
'us-ascii',
],
'iso-8859-2': [
'csisolatin2',
'iso-ir-101',
Expand Down Expand Up @@ -170,21 +185,7 @@ const { getEncodingFromLabel } = require('internal/encoding');
'x-cp1251',
],
'windows-1252': [
'ansi_x3.4-1968',
'ascii',
'cp1252',
'cp819',
'csisolatin1',
'ibm819',
'iso-8859-1',
'iso-ir-100',
'iso8859-1',
'iso88591',
'iso_8859-1',
'iso_8859-1:1987',
'l1',
'latin1',
'us-ascii',
'x-cp1252',
],
'windows-1253': [
Expand Down Expand Up @@ -281,6 +282,7 @@ const { getEncodingFromLabel } = require('internal/encoding');
Object.entries(mappings).forEach((i) => {
const enc = i[0];
const labels = i[1];
console.log("label: ",enc, "enc: ", getEncodingFromLabel(enc))
assert.strictEqual(getEncodingFromLabel(enc), enc);
labels.forEach((l) => assert.strictEqual(getEncodingFromLabel(l), enc));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

// From: https://github.com/w3c/web-platform-tests/blob/39a67e2fff/encoding/textdecoder-fatal.html
// With the twist that we specifically test for Node.js error codes

const common = require('../common');

if (!common.hasIntl)
common.skip('missing Intl');

const assert = require('assert');

{
// Windows-1252 mapping for bytes 0x7F-0x9F as [byte, unicode code point]
const win1252_0x7F_0x9F = [
[0x7F, 0x007F], // DELETE
[0x80, 0x20AC], // EURO SIGN
[0x81, 0x0081], // UNDEFINED
[0x82, 0x201A], // SINGLE LOW-9 QUOTATION MARK
[0x83, 0x0192], // LATIN SMALL LETTER F WITH HOOK
[0x84, 0x201E], // DOUBLE LOW-9 QUOTATION MARK
[0x85, 0x2026], // HORIZONTAL ELLIPSIS
[0x86, 0x2020], // DAGGER
[0x87, 0x2021], // DOUBLE DAGGER
[0x88, 0x02C6], // CIRCUMFLEX
[0x89, 0x2030], // PER MILLE SIGN
[0x8A, 0x0160], // LATIN CAPITAL LETTER S WITH CARON
[0x8B, 0x2039], // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
[0x8C, 0x0152], // LATIN CAPITAL LIGATURE OE
[0x8D, 0x008D], // UNDEFINED
[0x8E, 0x017D], // LATIN CAPITAL LETTER Z WITH CARON
[0x8F, 0x008F], // UNDEFINED
[0x90, 0x0090], // UNDEFINED
[0x91, 0x2018], // LEFT SINGLE QUOTATION MARK
[0x92, 0x2019], // RIGHT SINGLE QUOTATION MARK
[0x93, 0x201C], // LEFT DOUBLE QUOTATION MARK
[0x94, 0x201D], // RIGHT DOUBLE QUOTATION MARK
[0x95, 0x2022], // BULLET
[0x96, 0x2013], // EN DASH
[0x97, 0x2014], // EM DASH
[0x98, 0x02DC], // SMALL TILDE
[0x99, 0x2122], // TRADE MARK SIGN
[0x9A, 0x0161], // LATIN SMALL LETTER S WITH CARON
[0x9B, 0x203A], // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
[0x9C, 0x0153], // LATIN SMALL LIGATURE OE
[0x9D, 0x009D], // UNDEFINED
[0x9E, 0x017E], // LATIN SMALL LETTER Z WITH CARON
[0x9F, 0x0178] // LATIN CAPITAL LETTER Y WITH DIAERESIS
];

for (let i = 0; i < win1252_0x7F_0x9F.length; i++) {
const byte = win1252_0x7F_0x9F[i][0];
const expectedUnicodeCode = win1252_0x7F_0x9F[i][1];
const arr = new Uint8Array([byte]);
let decoded;
assert.doesNotThrow(() => {
decoded = new TextDecoder("windows-1252").decode(arr);
}, `Decoding byte ${byte} should not throw`);
assert.strictEqual(decoded.length, 1, `Decoded string for ${byte} should have length 1`);
const actualUnicodeCode = decoded.codePointAt(0);
assert.strictEqual(actualUnicodeCode, expectedUnicodeCode, `Decoded code point for ${byte} should be U+${expectedUnicodeCode.toString(16).toUpperCase()}`);
}
}