Skip to content

Commit

Permalink
fix: ensure that files/folders whose names are properties of Object.p…
Browse files Browse the repository at this point in the history
…rototype 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
  • Loading branch information
erikian authored Sep 27, 2023
1 parent bd8e23f commit ecde48e
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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]
}
Expand All @@ -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]
}
Expand All @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions test/api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
Binary file added test/expected/packthis-object-prototype.asar
Binary file not shown.
1 change: 1 addition & 0 deletions test/input/packthis-object-prototype/__proto__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__proto__
1 change: 1 addition & 0 deletions test/input/packthis-object-prototype/constructor/__proto__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
constructor/__proto__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
constructor/constructor
1 change: 1 addition & 0 deletions test/input/packthis-object-prototype/constructor/file1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
constructor/file1
1 change: 1 addition & 0 deletions test/input/packthis-object-prototype/file1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file1
1 change: 1 addition & 0 deletions test/input/packthis-object-prototype/file2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
folder1/constructor/constructor/__proto__/__proto__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
folder1/constructor/constructor/__proto__/file1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
folder1/constructor/constructor/constructor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
folder1/constructor/constructor/file1
1 change: 1 addition & 0 deletions test/input/packthis-object-prototype/folder1/file1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
folder1/file1

0 comments on commit ecde48e

Please sign in to comment.