bower / decompress-zip

Module that decompresses zip files
MIT License
102 stars 76 forks source link

Exception when using strip:1 #25

Closed georgzoeller closed 9 years ago

georgzoeller commented 10 years ago

decompress-zip:0.0.6: Extracting a simple zip file with one level of empty directory at the root will throw an TypeError on path.join decompress-zip.js:259 if strip:1 is set

DecompressZip.prototype.extractFile = function (file, options) {
var destination = path.join(options.path, file.path);

The issue is in decompress-zip.js:109..120, which, instead of adding .path to the file entry, is returning the path directly in files.map().

files = files.map(function (file) {
                if (file.type !== 'Directory') {
...
                    return file.path //<-- this is replacing file with file.path in the map.
                    // should be:
                    //   file.path = path.join(dir.join(path.sep), filename);
                    //   return file

                }

Note: The current tests do not detect the issue as they do not validate the feature at all - they just test strip to see if an exception is thrown for the 'stripping too deep' case. Ideally, the stripping too deep test case should validate the exact exception expected and a new test case with strip:1 should be added.

georgzoeller commented 10 years ago

On further inspection, it is becoming more clear that this code has never run, there's more wrong with it.

The if () filter inside the .map function generates undefined entries in the returned path array for any directory in the zip structure, so even with my fix, only zip files that don't have a sub directory structure will successfully extract. All other's will fail further down the chain when file.path is tested against the first undefined entry.

wenbing commented 10 years ago

I got this problem too

sindresorhus commented 9 years ago

https://github.com/bower/decompress-zip/pull/31