Fixes #499: Add a test for truncate when length is NaN
This change to fs.truncate()'s functionality raises an error when the supplied length variable is (1) not a valid integer, or, (2) not a positive integer.
This commit is contained in:
parent
fd3de6be2c
commit
d81594de98
|
@ -1277,7 +1277,10 @@ function truncate_file(context, path, length, callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(length < 0) {
|
if (!Number.isInteger(length)) {
|
||||||
|
callback(new Errors.EINVAL('length must be a number'));
|
||||||
|
}
|
||||||
|
else if (length < 0) {
|
||||||
callback(new Errors.EINVAL('length cannot be negative'));
|
callback(new Errors.EINVAL('length cannot be negative'));
|
||||||
} else {
|
} else {
|
||||||
find_node(context, path, read_file_data);
|
find_node(context, path, read_file_data);
|
||||||
|
|
|
@ -25,6 +25,21 @@ describe('fs.truncate', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should error when length is NaN', function(done) {
|
||||||
|
var fs = util.fs();
|
||||||
|
var contents = 'This is a file.';
|
||||||
|
|
||||||
|
fs.writeFile('/myfile', contents, function(error) {
|
||||||
|
if(error) throw error;
|
||||||
|
|
||||||
|
fs.truncate('/myfile', 'NaN', function(error) {
|
||||||
|
expect(error).to.exist;
|
||||||
|
expect(error.code).to.equal('EINVAL');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should error when path is not a file', function(done) {
|
it('should error when path is not a file', function(done) {
|
||||||
var fs = util.fs();
|
var fs = util.fs();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue