Merge pull request #271 from gideonthomas/issue270

Fix #270 - pathCheck should handle undefined paths
This commit is contained in:
Alan K 2014-08-22 12:31:32 -04:00
commit e79a6302ce
3 changed files with 34 additions and 2 deletions

View File

@ -1550,10 +1550,13 @@ function validate_file_options(options, enc, fileMode){
function pathCheck(path, callback) { function pathCheck(path, callback) {
var err; 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); err = new Errors.EINVAL('Path must be a string without null bytes.', path);
} else if(!isAbsolutePath(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) { if(err) {

28
tests/bugs/issue270.js Normal file
View File

@ -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();
});
});
});

View File

@ -75,3 +75,4 @@ require("./bugs/issue247.js");
require("./bugs/issue254.js"); require("./bugs/issue254.js");
require("./bugs/issue258.js"); require("./bugs/issue258.js");
require("./bugs/issue267.js"); require("./bugs/issue267.js");
require("./bugs/issue270.js");