-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: (+/-)Infinity and NaN invalid unixtimestamp
Infinity and NaN are currently considered valid input when generating a unix time stamp but are defaulted arbitrarly to Date.now()/1000. This PR removes this behaviour and throw an exception like all the other invalid input types. PR-URL: #11919 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
ae8a869
commit eed87b1
Showing
4 changed files
with
11 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
|
||
[undefined, null, []].forEach((input) => { | ||
[Infinity, -Infinity, NaN].forEach((input) => { | ||
assert.throws(() => fs._toUnixTimestamp(input), | ||
new RegExp('^Error: Cannot parse time: ' + input + '$')); | ||
}); | ||
|
||
assert.throws(() => fs._toUnixTimestamp({}), | ||
/^Error: Cannot parse time: \[object Object\]$/); | ||
|
||
[1, '1', Date.now(), -1, '-1', Infinity].forEach((input) => { | ||
const okInputs = [1, -1, '1', '-1', Date.now()]; | ||
okInputs.forEach((input) => { | ||
assert.doesNotThrow(() => fs._toUnixTimestamp(input)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters