Skip to content

Commit ca7aa6c

Browse files
committed
Add support for iso-8850-2 in response body filtering code
Related issue: uBlockOrigin/uAssets#35031
1 parent aaefbdb commit ca7aa6c

1 file changed

Lines changed: 46 additions & 2 deletions

File tree

‎src/js/text-encode.js‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const textEncode = (( ) => {
3737
[ 'windows-1250', 'windows-1250' ],
3838
[ 'cp1250', 'windows-1250' ],
3939
[ 'x-cp1250', 'windows-1250' ],
40-
[ 'iso-8859-2', 'windows-1250' ],
4140

4241
[ 'windows-1251', 'windows-1251' ],
4342
[ 'cp1251', 'windows-1251' ],
@@ -60,6 +59,8 @@ const textEncode = (( ) => {
6059
[ 'latin1', 'windows-1252' ],
6160
[ 'us-ascii', 'windows-1252' ],
6261
[ 'x-cp1252', 'windows-1252' ],
62+
63+
[ 'iso-8859-2', 'iso-8859-2' ],
6364
]);
6465

6566
// http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT
@@ -124,6 +125,24 @@ const textEncode = (( ) => {
124125
/* 0x2038 */ 0x00, 0x8B, 0x9B, 0x00, 0x00, 0x00, 0x00, 0x00
125126
]);
126127

128+
const iso_8859_2 = new Map([
129+
[ 0x0104, 0xA1 ], [ 0x02D8, 0xA2 ], [ 0x0141, 0xA3 ], [ 0x013D, 0xA5 ],
130+
[ 0x015A, 0xA6 ], [ 0x0160, 0xA9 ], [ 0x015E, 0xAA ], [ 0x0164, 0xAB ],
131+
[ 0x0179, 0xAC ], [ 0x017D, 0xAE ], [ 0x017B, 0xAF ], [ 0x0105, 0xB1 ],
132+
[ 0x02DB, 0xB2 ], [ 0x0142, 0xB3 ], [ 0x013E, 0xB5 ], [ 0x015B, 0xB6 ],
133+
[ 0x02C7, 0xB7 ], [ 0x0161, 0xB9 ], [ 0x015F, 0xBA ], [ 0x0165, 0xBB ],
134+
[ 0x017A, 0xBC ], [ 0x02DD, 0xBD ], [ 0x017E, 0xBE ], [ 0x017C, 0xBF ],
135+
[ 0x0154, 0xC0 ], [ 0x0102, 0xC3 ], [ 0x0139, 0xC5 ], [ 0x0106, 0xC6 ],
136+
[ 0x010C, 0xC8 ], [ 0x0118, 0xCA ], [ 0x011A, 0xCC ], [ 0x010E, 0xCF ],
137+
[ 0x0110, 0xD0 ], [ 0x0143, 0xD1 ], [ 0x0147, 0xD2 ], [ 0x0150, 0xD5 ],
138+
[ 0x0158, 0xD8 ], [ 0x016E, 0xD9 ], [ 0x0170, 0xDB ], [ 0x0162, 0xDE ],
139+
[ 0x0155, 0xE0 ], [ 0x0103, 0xE3 ], [ 0x013A, 0xE5 ], [ 0x0107, 0xE6 ],
140+
[ 0x010D, 0xE8 ], [ 0x0119, 0xEA ], [ 0x011B, 0xEC ], [ 0x010F, 0xEF ],
141+
[ 0x0111, 0xF0 ], [ 0x0144, 0xF1 ], [ 0x0148, 0xF2 ], [ 0x0151, 0xF5 ],
142+
[ 0x0159, 0xF8 ], [ 0x016F, 0xF9 ], [ 0x0171, 0xFB ], [ 0x0163, 0xFE ],
143+
[ 0x02D9, 0xFF ],
144+
]);
145+
127146
const encoders = {
128147
'windows-1250': function(buf) {
129148
let i = 0, n = buf.byteLength, o = 0, c;
@@ -247,7 +266,32 @@ const textEncode = (( ) => {
247266
}
248267
}
249268
return buf.slice(0, o);
250-
}
269+
},
270+
'iso-8859-2': function(buf) {
271+
let i = 0, n = buf.byteLength, o = 0, c;
272+
while ( i < n ) {
273+
c = buf[i++];
274+
if ( c < 0x80 ) {
275+
buf[o++] = c;
276+
} else {
277+
if ( (c & 0xE0) === 0xC0 ) {
278+
c = (c & 0x1F) << 6;
279+
c |= (buf[i++] & 0x3F);
280+
} else if ( (c & 0xF0) === 0xE0 ) {
281+
c = (c & 0x0F) << 12;
282+
c |= (buf[i++] & 0x3F) << 6;
283+
c |= (buf[i++] & 0x3F);
284+
} else if ( (c & 0xF8) === 0xF0 ) {
285+
c = (c & 0x07) << 18;
286+
c |= (buf[i++] & 0x3F) << 12;
287+
c |= (buf[i++] & 0x3F) << 6;
288+
c |= (buf[i++] & 0x3F);
289+
}
290+
buf[o++] = (iso_8859_2.get(c) ?? c) & 0xFF;
291+
}
292+
}
293+
return buf.slice(0, o);
294+
},
251295
};
252296

253297
return {

0 commit comments

Comments
 (0)