Skip to content

Commit ecde48e

Browse files
authored
fix: ensure that files/folders whose names are properties of Object.prototype are packaged/extracted correctly (#253)
* fix: ensure that files/folders whose names are properties of Object.prototype are packaged/extracted correctly * fix: directory name case * fix: remove trailing line endings
1 parent bd8e23f commit ecde48e

File tree

14 files changed

+24
-5
lines changed

14 files changed

+24
-5
lines changed

lib/filesystem.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const pipeline = promisify(stream.pipeline)
1414
class Filesystem {
1515
constructor (src) {
1616
this.src = path.resolve(src)
17-
this.header = { files: {} }
17+
this.header = { files: Object.create(null) }
1818
this.offset = BigInt(0)
1919
}
2020

@@ -24,7 +24,7 @@ class Filesystem {
2424
for (const dir of dirs) {
2525
if (dir !== '.') {
2626
if (!json.files[dir]) {
27-
json.files[dir] = { files: {} }
27+
json.files[dir] = { files: Object.create(null) }
2828
}
2929
json = json.files[dir]
3030
}
@@ -38,10 +38,10 @@ class Filesystem {
3838
const name = path.basename(p)
3939
const node = this.searchNodeFromDirectory(path.dirname(p))
4040
if (node.files == null) {
41-
node.files = {}
41+
node.files = Object.create(null)
4242
}
4343
if (node.files[name] == null) {
44-
node.files[name] = {}
44+
node.files[name] = Object.create(null)
4545
}
4646
return node.files[name]
4747
}
@@ -51,7 +51,7 @@ class Filesystem {
5151
if (shouldUnpack) {
5252
node.unpacked = shouldUnpack
5353
}
54-
node.files = node.files || {}
54+
node.files = node.files || Object.create(null)
5555
return node.files
5656
}
5757

test/api-spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,12 @@ describe('api', function () {
9494
const expected = await fs.readFile('test/input/packthis-unicode-path/dir1/女の子.txt', 'utf8')
9595
return compFileLists(actual, expected)
9696
})
97+
it('should create files/directories whose names are properties of Object.prototype', async () => {
98+
await asar.createPackage('test/input/packthis-object-prototype/', 'tmp/packthis-object-prototype.asar')
99+
return compFiles('tmp/packthis-object-prototype.asar', 'test/expected/packthis-object-prototype.asar')
100+
})
101+
it('should extract files/directories whose names are properties of Object.prototype', () => {
102+
asar.extractAll('test/expected/packthis-object-prototype.asar', 'tmp/packthis-object-prototype/')
103+
return compDirs('test/input/packthis-object-prototype/', 'tmp/packthis-object-prototype')
104+
})
97105
})
3.03 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__proto__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
constructor/__proto__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
constructor/constructor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
constructor/file1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
folder1/constructor/constructor/__proto__/__proto__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
folder1/constructor/constructor/__proto__/file1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
folder1/constructor/constructor/constructor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
folder1/constructor/constructor/file1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
folder1/file1

0 commit comments

Comments
 (0)