mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 03:12:57 +00:00

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: https://github.com/nodejs/node/pull/11919 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
18 lines
524 B
JavaScript
18 lines
524 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const fs = require('fs');
|
|
const assert = require('assert');
|
|
|
|
[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\]$/);
|
|
|
|
const okInputs = [1, -1, '1', '-1', Date.now()];
|
|
okInputs.forEach((input) => {
|
|
assert.doesNotThrow(() => fs._toUnixTimestamp(input));
|
|
});
|