Skip to content

Commit

Permalink
0.4.12 - Fix additional issue with extractEntryTo improperly handling…
Browse files Browse the repository at this point in the history
… directory children.
  • Loading branch information
cjacobs committed Jun 21, 2018
1 parent a5f3ad7 commit d2e7512
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions adm-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ module.exports = function (/*String*/input) {
if (!content) {
throw Utils.Errors.CANT_EXTRACT_FILE;
}
var childName = sanitize(targetPath, child.entryName);
var childName = sanitize(targetPath, maintainEntryPath ? child.entryName : pth.basename(child.entryName));

Utils.writeFileTo(pth.resolve(targetPath, maintainEntryPath ? childName : childName.substr(entryName.length)), content, overwrite);
Utils.writeFileTo(childName, content, overwrite);
});
return true;
}
Expand Down
26 changes: 20 additions & 6 deletions test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('adm-zip', () => {
"./test/xxx/utes_test/New folder/somefile.txt"
].sort());
})
it('zip.extractEntryTo()', () => {

it('zip.extractEntryTo(entry, destination, false, true)', () => {
const destination = './test/xxx'
const zip = new Zip('./test/assets/ultra.zip');
var zipEntries = zip.getEntries();
Expand All @@ -43,12 +44,25 @@ describe('adm-zip', () => {
"./test/xxx/hidden.txt",
"./test/xxx/hidden_readonly.txt",
"./test/xxx/New Text Document.txt",
"./test/xxx/ojects/adm-zip/test/xxx/attributes_test/New folder/hidden.txt",
"./test/xxx/ojects/adm-zip/test/xxx/attributes_test/New folder/hidden_readonly.txt",
"./test/xxx/ojects/adm-zip/test/xxx/attributes_test/New folder/readonly.txt",
"./test/xxx/readonly.txt",
"./test/xxx/somefile.txt",
"./test/xxx/stormProjects/adm-zip/test/xxx/attributes_test/asd/New Text Document.txt"
"./test/xxx/somefile.txt"
].sort());
})

it('zip.extractEntryTo(entry, destination, true, true)', () => {
const destination = './test/xxx'
const zip = new Zip('./test/assets/ultra.zip');
var zipEntries = zip.getEntries();
zipEntries.forEach(e => zip.extractEntryTo(e, destination, true, true));

const files = walk(destination)
expect(files.sort()).to.deep.equal([
"./test/xxx/attributes_test/asd/New Text Document.txt",
"./test/xxx/attributes_test/blank file.txt",
"./test/xxx/attributes_test/New folder/hidden.txt",
"./test/xxx/attributes_test/New folder/hidden_readonly.txt",
"./test/xxx/attributes_test/New folder/readonly.txt",
"./test/xxx/utes_test/New folder/somefile.txt"
].sort());
})
})
Expand Down

0 comments on commit d2e7512

Please sign in to comment.