diff --git a/lib/index.js b/lib/index.js index b4498772..b4c95bad 100644 --- a/lib/index.js +++ b/lib/index.js @@ -19,7 +19,10 @@ function JSZip() { // "folder/" : {...}, // "folder/data.txt" : {...} // } - this.files = {}; + // NOTE: we use a null prototype because we do not + // want filenames like "toString" coming from a zip file + // to overwrite methods and attributes in a normal Object. + this.files = Object.create(null); this.comment = null; diff --git a/lib/object.js b/lib/object.js index 1c9d8e80..aec3db78 100644 --- a/lib/object.js +++ b/lib/object.js @@ -179,16 +179,16 @@ var out = { */ forEach: function(cb) { var filename, relativePath, file; + /* jshint ignore:start */ + // ignore warning about unwanted properties because this.files is a null prototype object for (filename in this.files) { - if (!this.files.hasOwnProperty(filename)) { - continue; - } file = this.files[filename]; relativePath = filename.slice(this.root.length, filename.length); if (relativePath && filename.slice(0, this.root.length) === this.root) { // the file is in the current root cb(relativePath, file); // TODO reverse the parameters ? need to be clean AND consistent with the filter search fn... } } + /* jshint ignore:end */ }, /**