Skip to content

Commit

Permalink
Merge pull request #327 from kosuke-suzuki/multibyte-comment
Browse files Browse the repository at this point in the history
Inappropriate ZIP comment length in multibyte case; Fixed it
  • Loading branch information
cthackers authored Nov 19, 2020
2 parents a7e8932 + 1a334b2 commit 49218a4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.4.16",
"description": "Javascript implementation of zip for nodejs with support for electron original-fs. Allows user to create or extract zip files both in memory or to/from disk",
"scripts": {
"test": "mocha test/mocha.js test/crc/index.js"
"test": "mocha test/mocha.js test/crc/index.js test/multibyte/test.js"
},
"keywords": [
"zip",
Expand Down
24 changes: 24 additions & 0 deletions test/multibyte/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { expect } = require("chai");
const Utils = require("../../util");
const AdmZip = require("../../adm-zip");
const path = require("path");

describe('adm-zip', () => {
it('adds multibyte ZIP comment in UTF-8 with appropriate byte', () => {
const zip = new AdmZip();
zip.addLocalFile(
path.join(__dirname, "./じっぷ/じっぷ.txt")
);
zip.addZipComment("じっぷ");
const willSend = zip.toBuffer();
const end = willSend.slice(
willSend.lastIndexOf(Utils.Constants.ENDSIG)
);
const commentLength = end.readInt16LE(Utils.Constants.ENDCOM, 2);
expect(commentLength).to.eq(9);
const expected = Buffer.from("じっぷ");
const actual = end.slice(Utils.Constants.ENDCOM + 2);
expect(actual).to.include(expected);
expect(expected).to.include(actual);
});
});
Binary file added test/multibyte/じっぷ.zip
Binary file not shown.
1 change: 1 addition & 0 deletions test/multibyte/じっぷ/じっぷ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
じっぷ
4 changes: 2 additions & 2 deletions zipFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ module.exports = function (/*String|Buffer*/input, /*Number*/inputType) {
return _comment.toString();
},
set comment(val) {
mainHeader.commentLength = val.length;
_comment = val;
_comment = Utils.toBuffer(val);
mainHeader.commentLength = _comment.length;
},

getEntryCount: function() {
Expand Down

0 comments on commit 49218a4

Please sign in to comment.