Skip to content

Commit

Permalink
check if file list is empty in add function
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelghaniiTassi committed Aug 1, 2017
1 parent 0eec772 commit abba17f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ module.exports = function (archive, files, options) {
// Convert array of files into a string if needed.
files = u.files(files);



// Check if file list is empty
//remove quotes
var fileList = files.substring(1, files.length-1);
//trim and check if the list is empty
if (fileList.trim().length == 0) {
return reject(new Error('File list should not be empty'));
}

var command = '7z a "' + archive + '" ' + files;

// Start the command
Expand Down
16 changes: 16 additions & 0 deletions test/lib/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ describe('Method: `Zip.add`', function () {
});
});

it('should return an error if file list is empty', function(done) {
add('.tmp/test/add.zip', '')
.catch(function (err) {
expect(err).to.be.an.instanceof(Error);
done();
});
});

it('should return an error if file list is empty or having hust space characters', function(done) {
add('.tmp/test/add.zip', ' ')
.catch(function (err) {
expect(err).to.be.an.instanceof(Error);
done();
});
});

it('should accept array as source', function (done) {
var store = [];
add('.tmp/test/add.zip', ['*.md', '*.js'])
Expand Down

0 comments on commit abba17f

Please sign in to comment.