Skip to content

Commit ee0acb8

Browse files
committed
fixed windows-1255 \u05BA decoding
1 parent 40991f4 commit ee0acb8

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/coders/single-byte/SingleByteDecoder.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Stream } from "../../common/Stream";
22
import { decoderError } from "../../encoding/encodings";
33
import { finished } from "../../encoding/finished";
4-
import { index } from "../../encoding/indexes";
54
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
65

76
/**
@@ -14,7 +13,7 @@ export class SingleByteDecoder {
1413

1514
readonly fatal: boolean;
1615

17-
constructor(index: Array<number>, options: { fatal: boolean; }) {
16+
constructor(private readonly index: Array<number>, options: { fatal: boolean; }) {
1817
this.fatal = options.fatal;
1918
}
2019

@@ -37,10 +36,10 @@ export class SingleByteDecoder {
3736

3837
// 3. Let code point be the index code point for byte − 0x80 in
3938
// index single-byte.
40-
const code_point = index[bite - 0x80];
39+
const code_point = this.index[bite - 0x80];
4140

4241
// 4. If code point is null, return error.
43-
if (code_point === null)
42+
if (!code_point)
4443
return decoderError(this.fatal);
4544

4645
// 5. Return a code point whose value is code point.

src/common/TextDecoder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class TextDecoder {
178178
if (result === finished)
179179
break;
180180

181-
if (result !== null) {
181+
if (result) {
182182
if (Array.isArray(result))
183183
output.push.apply(output, /**@type {!Array.<number>}*/(result));
184184
else
@@ -196,7 +196,7 @@ export class TextDecoder {
196196
result = this._decoder.handler(input_stream, input_stream.read());
197197
if (result === finished)
198198
break;
199-
if (result === null)
199+
if (!result)
200200
continue;
201201
if (Array.isArray(result))
202202
output.push.apply(output, /**@type {!Array.<number>}*/(result));

test/browser/test-misc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ test(function() {
386386
assert_array_equals([].slice.call(encoder.encode(0)), [48]);
387387
}, 'encode() called with falsy arguments (polyfill bindings)');
388388

389-
// test(function() {
390-
// // Regression test for https://github.com/inexorabletash/text-encoding/issues/59
391-
// assert_array_equals(
392-
// new TextEncoding.TextDecoder('windows-1255').decode(new Uint8Array([0xCA])), '\u05BA');
393-
// }, 'windows-1255 map 0xCA to U+05BA');
389+
test(function() {
390+
// Regression test for https://github.com/inexorabletash/text-encoding/issues/59
391+
assert_array_equals(
392+
new TextEncoding.TextDecoder('windows-1255').decode(new Uint8Array([0xCA])), '\u05BA');
393+
}, 'windows-1255 map 0xCA to U+05BA');

test/node/test-misc.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ describe('Miscellaneous tests', () => {
399399
assert_array_equals([].slice.call(encoder.encode(0)), [48]);
400400
});
401401

402-
it.skip('windows-1255 map 0xCA to U+05BA', () => {
402+
it('windows-1255 map 0xCA to U+05BA', () => {
403403
// Regression test for https://github.com/inexorabletash/text-encoding/issues/59
404404
assert_equals(
405-
new TextDecoder('windows-1255').decode(new Uint8Array([0xCD])),
405+
new TextDecoder('windows-1255').decode(new Uint8Array([0xCA])),
406406
'\u05BA'
407407
);
408408
});

0 commit comments

Comments
 (0)