diff --git a/lib/filesystem.js b/lib/filesystem.js index 908b0dd..ce10245 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -14,7 +14,7 @@ const pipeline = promisify(stream.pipeline) class Filesystem { constructor (src) { this.src = path.resolve(src) - this.header = { files: {} } + this.header = { files: Object.create(null) } this.offset = BigInt(0) } @@ -24,7 +24,7 @@ class Filesystem { for (const dir of dirs) { if (dir !== '.') { if (!json.files[dir]) { - json.files[dir] = { files: {} } + json.files[dir] = { files: Object.create(null) } } json = json.files[dir] } @@ -38,10 +38,10 @@ class Filesystem { const name = path.basename(p) const node = this.searchNodeFromDirectory(path.dirname(p)) if (node.files == null) { - node.files = {} + node.files = Object.create(null) } if (node.files[name] == null) { - node.files[name] = {} + node.files[name] = Object.create(null) } return node.files[name] } @@ -51,7 +51,7 @@ class Filesystem { if (shouldUnpack) { node.unpacked = shouldUnpack } - node.files = node.files || {} + node.files = node.files || Object.create(null) return node.files } diff --git a/test/api-spec.js b/test/api-spec.js index 3d4f5ce..d50323d 100644 --- a/test/api-spec.js +++ b/test/api-spec.js @@ -94,4 +94,12 @@ describe('api', function () { const expected = await fs.readFile('test/input/packthis-unicode-path/dir1/女の子.txt', 'utf8') return compFileLists(actual, expected) }) + it('should create files/directories whose names are properties of Object.prototype', async () => { + await asar.createPackage('test/input/packthis-object-prototype/', 'tmp/packthis-object-prototype.asar') + return compFiles('tmp/packthis-object-prototype.asar', 'test/expected/packthis-object-prototype.asar') + }) + it('should extract files/directories whose names are properties of Object.prototype', () => { + asar.extractAll('test/expected/packthis-object-prototype.asar', 'tmp/packthis-object-prototype/') + return compDirs('test/input/packthis-object-prototype/', 'tmp/packthis-object-prototype') + }) }) diff --git a/test/expected/packthis-object-prototype.asar b/test/expected/packthis-object-prototype.asar new file mode 100644 index 0000000..a7bad8c Binary files /dev/null and b/test/expected/packthis-object-prototype.asar differ diff --git a/test/input/packthis-object-prototype/__proto__ b/test/input/packthis-object-prototype/__proto__ new file mode 100644 index 0000000..84437e7 --- /dev/null +++ b/test/input/packthis-object-prototype/__proto__ @@ -0,0 +1 @@ +__proto__ \ No newline at end of file diff --git a/test/input/packthis-object-prototype/constructor/__proto__ b/test/input/packthis-object-prototype/constructor/__proto__ new file mode 100644 index 0000000..bd07bcf --- /dev/null +++ b/test/input/packthis-object-prototype/constructor/__proto__ @@ -0,0 +1 @@ +constructor/__proto__ \ No newline at end of file diff --git a/test/input/packthis-object-prototype/constructor/constructor b/test/input/packthis-object-prototype/constructor/constructor new file mode 100644 index 0000000..4c4cc0c --- /dev/null +++ b/test/input/packthis-object-prototype/constructor/constructor @@ -0,0 +1 @@ +constructor/constructor \ No newline at end of file diff --git a/test/input/packthis-object-prototype/constructor/file1 b/test/input/packthis-object-prototype/constructor/file1 new file mode 100644 index 0000000..7d188b0 --- /dev/null +++ b/test/input/packthis-object-prototype/constructor/file1 @@ -0,0 +1 @@ +constructor/file1 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/file1 b/test/input/packthis-object-prototype/file1 new file mode 100644 index 0000000..08219db --- /dev/null +++ b/test/input/packthis-object-prototype/file1 @@ -0,0 +1 @@ +file1 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/file2 b/test/input/packthis-object-prototype/file2 new file mode 100644 index 0000000..30d67d4 --- /dev/null +++ b/test/input/packthis-object-prototype/file2 @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ new file mode 100644 index 0000000..1cd727b --- /dev/null +++ b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ @@ -0,0 +1 @@ +folder1/constructor/constructor/__proto__/__proto__ \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 new file mode 100644 index 0000000..c9cb751 --- /dev/null +++ b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 @@ -0,0 +1 @@ +folder1/constructor/constructor/__proto__/file1 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/constructor/constructor/constructor b/test/input/packthis-object-prototype/folder1/constructor/constructor/constructor new file mode 100644 index 0000000..757c3ea --- /dev/null +++ b/test/input/packthis-object-prototype/folder1/constructor/constructor/constructor @@ -0,0 +1 @@ +folder1/constructor/constructor/constructor \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/constructor/constructor/file1 b/test/input/packthis-object-prototype/folder1/constructor/constructor/file1 new file mode 100644 index 0000000..3b0d002 --- /dev/null +++ b/test/input/packthis-object-prototype/folder1/constructor/constructor/file1 @@ -0,0 +1 @@ +folder1/constructor/constructor/file1 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/file1 b/test/input/packthis-object-prototype/folder1/file1 new file mode 100644 index 0000000..b3ce553 --- /dev/null +++ b/test/input/packthis-object-prototype/folder1/file1 @@ -0,0 +1 @@ +folder1/file1 \ No newline at end of file