Skip to content

Commit

Permalink
Merge pull request electron#159 from Appuls/Appuls/bugfix/createPacka…
Browse files Browse the repository at this point in the history
…geFromFiles-regression

fix: Normalized filepaths in createPackageFromFiles
  • Loading branch information
Cheng Zhao authored Oct 9, 2018
2 parents b32cb84 + b4eeb46 commit c2d3d86
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/asar.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ callback: The callback function. Accepts (err).
module.exports.createPackageFromFiles = function (src, dest, filenames, metadata, options, callback) {
if (typeof metadata === 'undefined' || metadata === null) { metadata = {} }
if (typeof options === 'undefined' || options === null) { options = {} }

src = path.normalize(src)
dest = path.normalize(dest)
filenames = filenames.map(function (filename) { return path.normalize(filename) })

const filesystem = new Filesystem(src)
const files = []
const unpackDirs = []
Expand Down
8 changes: 8 additions & 0 deletions test/api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ describe('api', function () {
done(compFiles('tmp/packthis-api.asar', 'test/expected/packthis.asar'))
})
})
if (os.platform() === 'win32') {
it('should create archive with windows-style path separators', function (done) {
asar.createPackage('test\\input\\packthis\\', 'tmp\\packthis-api.asar', function (error) {
if (error != null) return done(error)
done(compFiles('tmp/packthis-api.asar', 'test/expected/packthis.asar'))
})
})
}
it('should create archive from directory (without hidden files)', function (done) {
asar.createPackageWithOptions('test/input/packthis/', 'tmp/packthis-without-hidden-api.asar', {dot: false}, function (error) {
if (error != null) return done(error)
Expand Down
8 changes: 8 additions & 0 deletions test/cli-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ describe('command line interface', function () {
done(compFiles('tmp/packthis-cli.asar', 'test/expected/packthis.asar'))
})
})
if (os.platform() === 'win32') {
it('should create archive from directory with windows-style path separators', function (done) {
exec('node bin/asar p test\\input\\packthis\\ tmp\\packthis-cli.asar', function (error, stdout, stderr) {
if (error != null) return done(error)
done(compFiles('tmp/packthis-cli.asar', 'test/expected/packthis.asar'))
})
})
}
it('should create archive from directory without hidden files', function (done) {
exec('node bin/asar p test/input/packthis/ tmp/packthis-without-hidden-cli.asar --exclude-hidden', function (error, stdout, stderr) {
if (error != null) return done(error)
Expand Down

0 comments on commit c2d3d86

Please sign in to comment.