Skip to content

Commit 02bba08

Browse files
committed
Fixes #131
Creating dictionary without prototype to avoid prototype collisions from packed string
1 parent 1b64bdd commit 02bba08

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lzwCompress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
return uncompressed;
122122
}
123123
let i;
124-
const dictionary = {};
124+
const dictionary = Object.create(null);
125125
let c,
126126
wc,
127127
w = '';

test/spec/lzwCompress.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ describe('lzwCompress Tests', function () {
7676
expect(lzwCompress.unpack(lzwCompress.pack('"{\\"abnabnabn\\":\\"asd\\"}"'))).toEqual('"{\\"abnabnabn\\":\\"asd\\"}"'); // issue #1 - https://github.com/floydpink/lzwCompress.js/issues/1
7777
});
7878

79+
it('should pack/unpack objects with javascript while avoiding prototype methods', function() {
80+
var jsString = 'toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,toString,';
81+
82+
expect(lzwCompress.unpack(lzwCompress.pack(jsString))).toEqual(jsString);
83+
});
84+
7985
});
8086

8187
describe('arrays', function () {
@@ -96,7 +102,6 @@ describe('lzwCompress Tests', function () {
96102
expect(lzwCompress.unpack(lzwCompress.pack(obj2))).toEqual(obj2);
97103
expect(lzwCompress.unpack(lzwCompress.pack(obj3))).toEqual(obj3);
98104
});
99-
100105
});
101106

102107
describe('large json', function () {

0 commit comments

Comments
 (0)