Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure that files/folders whose names are properties of Object.prototype are packaged/extracted correctly #253

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__
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