| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a0cfb0c commit 469baa0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,6 +85,7 @@ const { | |||
| 85 | 85 | } = require('internal/constants'); | |
| 86 | 86 | const { | |
| 87 | 87 | isUint32, | |
| 88 | + validateInteger, | ||
| 88 | 89 | validateInt32, | |
| 89 | 90 | validateUint32 | |
| 90 | 91 | } = require('internal/validators'); | |
@@ -746,6 +747,7 @@ fs.truncate = function(path, len, callback) { | |||
| 746 | 747 | len = 0; | |
| 747 | 748 | } | |
| 748 | 749 | ||
| 750 | + validateInteger(len, 'len'); | ||
| 749 | 751 | callback = maybeCallback(callback); | |
| 750 | 752 | fs.open(path, 'r+', function(er, fd) { | |
| 751 | 753 | if (er) return callback(er); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -179,6 +179,16 @@ function testFtruncate(cb) { | |||
| 179 | 179 | process.on('exit', () => fs.closeSync(fd)); | |
| 180 | 180 | ||
| 181 | 181 | ['', false, null, {}, []].forEach((input) => { | |
| 182 | + assert.throws( | ||
| 183 | + () => fs.truncate(file5, input, common.mustNotCall()), | ||
| 184 | + { | ||
| 185 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 186 | + name: 'TypeError [ERR_INVALID_ARG_TYPE]', | ||
| 187 | + message: 'The "len" argument must be of type number. ' + | ||
| 188 | + `Received type ${typeof input}` | ||
| 189 | + } | ||
| 190 | + ); | ||
| 191 | + | ||
| 182 | 192 | assert.throws( | |
| 183 | 193 | () => fs.ftruncate(fd, input), | |
| 184 | 194 | { | |
@@ -191,6 +201,16 @@ function testFtruncate(cb) { | |||
| 191 | 201 | }); | |
| 192 | 202 | ||
| 193 | 203 | [-1.5, 1.5].forEach((input) => { | |
| 204 | + assert.throws( | ||
| 205 | + () => fs.truncate(file5, input), | ||
| 206 | + { | ||
| 207 | + code: 'ERR_OUT_OF_RANGE', | ||
| 208 | + name: 'RangeError [ERR_OUT_OF_RANGE]', | ||
| 209 | + message: 'The value of "len" is out of range. It must be ' + | ||
| 210 | + `an integer. Received ${input}` | ||
| 211 | + } | ||
| 212 | + ); | ||
| 213 | + | ||
| 194 | 214 | assert.throws( | |
| 195 | 215 | () => fs.ftruncate(fd, input), | |
| 196 | 216 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments