diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index aab3a1f..d3e6e9a 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1550,10 +1550,13 @@ function validate_file_options(options, enc, fileMode){ function pathCheck(path, callback) { var err; - if(isNullPath(path)) { + + if(!path) { + err = new Errors.EINVAL('Path must be a string', path); + } else if(isNullPath(path)) { err = new Errors.EINVAL('Path must be a string without null bytes.', path); } else if(!isAbsolutePath(path)) { - err = new Errors.EINAVL('Path must be absolute.', path); + err = new Errors.EINVAL('Path must be absolute.', path); } if(err) { diff --git a/tests/bugs/issue270.js b/tests/bugs/issue270.js new file mode 100644 index 0000000..21b4a23 --- /dev/null +++ b/tests/bugs/issue270.js @@ -0,0 +1,28 @@ +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; + +describe('undefined and relative paths, issue270', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should fail with EINVAL when called on an undefined path', function(done) { + var fs = util.fs(); + + fs.writeFile(undefined, 'data', function(err) { + expect(err).to.exist; + expect(err.code).to.equal('EINVAL'); + done(); + }); + }); + + it('should fail with EINVAL when called on a relative path', function(done) { + var fs = util.fs(); + + fs.writeFile('relpath/file.txt', 'data', function(err) { + expect(err).to.exist; + expect(err.code).to.equal('EINVAL'); + done(); + }); + }); +}); diff --git a/tests/index.js b/tests/index.js index 601a4a4..9155550 100644 --- a/tests/index.js +++ b/tests/index.js @@ -75,3 +75,4 @@ require("./bugs/issue247.js"); require("./bugs/issue254.js"); require("./bugs/issue258.js"); require("./bugs/issue267.js"); +require("./bugs/issue270.js");