Skip to content

Commit

Permalink
metadataPath validation replaces \ with / instead of complaining abou…
Browse files Browse the repository at this point in the history
…t it. closes #18"
  • Loading branch information
thejoshwolfe committed Dec 22, 2015
1 parent f52717a commit 5386c84
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function getEndOfCentralDirectoryRecord(self) {

function validateMetadataPath(metadataPath, isDirectory) {
if (metadataPath === "") throw new Error("empty metadataPath");
if (metadataPath.indexOf("\\") !== -1) throw new Error("invalid characters in path: " + metadataPath);
metadataPath = metadataPath.replace(/\\/g, "/");
if (/^[a-zA-Z]:/.test(metadataPath) || /^\//.test(metadataPath)) throw new Error("absolute path: " + metadataPath);
if (metadataPath.split("/").indexOf("..") !== -1) throw new Error("invalid relative path: " + metadataPath);
var looksLikeDirectory = /\/$/.test(metadataPath);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
},
"devDependencies": {
"bl": "~0.9.3",
"yauzl": "~2.0.0"
"yauzl": "~2.3.1"
}
}
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var BufferList = require("bl");
zipfile.addReadStream(fs.createReadStream(__filename), "readStream.txt", fileMetadata);
var expectedContents = fs.readFileSync(__filename);
zipfile.addBuffer(expectedContents, "with/directories.txt", fileMetadata);
zipfile.addBuffer(expectedContents, "with\\windows-paths.txt", fileMetadata);
zipfile.end(function(finalSize) {
if (finalSize !== -1) throw new Error("finalSize is impossible to know before compression");
zipfile.outputStream.pipe(new BufferList(function(err, data) {
Expand Down

0 comments on commit 5386c84

Please sign in to comment.