Skip to content

Commit 17e062c

Browse files
authored
fix: StringT: assume unknown encodings are 1-byte (#62)
- add a test for 'x-mac-roman' - add two utf-16 alias names - if an encoding is otherwise unknown, assume 1-byte length (this matches prior behavior) Fixes: #60
1 parent 6680114 commit 17e062c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/String.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ function encodingWidth(encoding) {
9898
return 1;
9999
case 'utf16le':
100100
case 'utf16-le':
101+
case 'utf-16be':
102+
case 'utf-16le':
101103
case 'utf16be':
102104
case 'utf16-be':
103105
case 'ucs2':
104106
return 2;
105107
default:
106-
throw new Error('Unknown encoding ' + encoding);
108+
//TODO: assume all other encodings are 1-byters
109+
//throw new Error('Unknown encoding ' + encoding);
110+
return 1;
107111
}
108112
}
109113

test/String.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ describe('String', function() {
5252
const string = new StringT(null, 'utf16le');
5353
assert.equal(string.fromBuffer(Buffer.from('🍻', 'utf16le')), '🍻');
5454
});
55+
56+
it('should decode x-mac-roman', function() {
57+
const string = new StringT(null, 'x-mac-roman');
58+
const buf = new Uint8Array([0x8a, 0x63, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x64, 0x20, 0x63, 0x68, 0x87, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x73]);
59+
assert.equal(string.fromBuffer(buf), 'äccented cháracters');
60+
})
5561
});
5662

5763
describe('size', function() {

0 commit comments

Comments
 (0)