diff --git a/lib/dest/index.js b/lib/dest/index.js index 8ac4344c..32f6deb1 100644 --- a/lib/dest/index.js +++ b/lib/dest/index.js @@ -7,6 +7,8 @@ var writeContents = require('./writeContents'); var defaultMode = 0777 & (~process.umask()); module.exports = function(outFolder, opt) { + if (typeof outFolder !== 'string') throw new Error('Invalid output folder'); + if (!opt) opt = {}; if (!opt.cwd) opt.cwd = process.cwd(); if (typeof opt.mode === 'string') opt.mode = parseInt(opt.mode, 8); diff --git a/lib/src/index.js b/lib/src/index.js index 90aad6e8..cad61053 100644 --- a/lib/src/index.js +++ b/lib/src/index.js @@ -5,7 +5,16 @@ var File = require('vinyl'); var getContents = require('./getContents'); var getStats = require('./getStats'); +var validateGlob = function(glob) { + var isArr = Array.isArray(glob); + if (typeof glob !== 'string' && !isArr) return false; + if (isArr && isArr.length === 0) return false; + return true; +}; + module.exports = function(glob, opt) { + if (!validateGlob(glob)) throw new Error('Invalid glob pattern'); + if (!opt) opt = {}; if (typeof opt.read !== 'boolean') opt.read = true; if (typeof opt.buffer !== 'boolean') opt.buffer = true; diff --git a/package.json b/package.json index fa4e5f95..3dfbe8f5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vinyl-fs", "description": "Vinyl adapter for the file system", - "version": "0.1.1", + "version": "0.1.2", "homepage": "http://github.com/wearefractal/vinyl-fs", "repository": "git://github.com/wearefractal/vinyl-fs.git", "author": "Fractal (http://wearefractal.com/)", @@ -9,7 +9,7 @@ "dependencies": { "vinyl": "^0.2.0", "glob-stream": "^3.1.5", - "glob-watcher": "^0.0.3", + "glob-watcher": "^0.0.4", "mkdirp": "^0.3.5", "graceful-fs": "^2.0.1", "map-stream": "^0.1.0" diff --git a/test/dest.js b/test/dest.js index 12d9f5e1..c7facd44 100644 --- a/test/dest.js +++ b/test/dest.js @@ -30,6 +30,17 @@ describe('dest stream', function() { beforeEach(wipeOut); afterEach(wipeOut); + it('should explode on invalid folder', function(done) { + var stream; + try { + stream = gulp.dest(); + } catch (err) { + should.exist(err); + should.not.exist(stream); + done(); + } + }); + it('should pass through writes with cwd', function(done) { var inputPath = path.join(__dirname, "./fixtures/test.coffee"); diff --git a/test/src.js b/test/src.js index 30b08006..587c3e9e 100644 --- a/test/src.js +++ b/test/src.js @@ -19,6 +19,39 @@ var dataWrap = function(fn) { describe('source stream', function() { + it('should explode on invalid glob (empty)', function(done) { + var stream; + try { + stream = gulp.src(); + } catch (err) { + should.exist(err); + should.not.exist(stream); + done(); + } + }); + + it('should explode on invalid glob (number)', function(done) { + var stream; + try { + stream = gulp.src(123); + } catch (err) { + should.exist(err); + should.not.exist(stream); + done(); + } + }); + + it('should explode on invalid glob (empty array)', function(done) { + var stream; + try { + stream = gulp.src([]); + } catch (err) { + should.exist(err); + should.not.exist(stream); + done(); + } + }); + it('should pass through writes', function(done) { var expectedPath = path.join(__dirname, "./fixtures/test.coffee"); var expectedContent = fs.readFileSync(expectedPath);