Skip to content

Commit

Permalink
zip: always convert filename to utf8. closes #41.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington committed Aug 18, 2013
1 parent 61f740c commit fa9d3ce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/headers/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

var inherits = require('util').inherits;
var iconv = require('iconv-lite');

function HeaderZip() {
this.bufferSize = 0;
Expand Down Expand Up @@ -60,7 +61,12 @@ HeaderZip.prototype.toObject = function(buf) {

HeaderZip.prototype._normalize = function(data) {
if (data.name) {
data.filenameLength = data.name.length;
var nameUTF8 = iconv.encode(data.name, 'utf8');
data.name = iconv.decode(nameUTF8, 'utf8');

data.filenameLength = nameUTF8.length;

data.flags |= (1<<11);
}

if (data.comment) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"mocha": "~1.12.0",
"rimraf": "~2.2.0",
"mkdirp": "~0.3.5",
"stream-bench": "~0.1.2"
"stream-bench": "~0.1.2",
"iconv-lite" : "~0.2.11"
},
"keywords": [
"archive",
Expand Down
20 changes: 20 additions & 0 deletions test/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,26 @@ describe('archiver', function() {
.append(binaryBuffer(20000), { name: 'buffer.txt', date: testDate })
.finalize();
});

it('should properly handle accented characters in filenames', function(done) {
var archive = archiver('zip', {
forceUTC: true
});

var testStream = new WriteHashStream('tmp/accentedchars-filenames.zip');

testStream.on('close', function() {
assert.equal(testStream.digest, '69194ccb7175d7fcfcb06c8cb0ed2c429dadb9f9');
done();
});

archive.pipe(testStream);

archive
.append(binaryBuffer(20000), { name: 'àáâãäçèéêëìíîïñòóôõöùúûüýÿ.txt', date: testDate })
.append(binaryBuffer(20000), { name: 'ÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ.txt', date: testDate2 })
.finalize();
});
});

});
Expand Down

0 comments on commit fa9d3ce

Please sign in to comment.