-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix invalid date output with util.inspect #6504
Conversation
@@ -14,6 +14,7 @@ assert.equal(util.inspect(null), 'null'); | |||
assert.equal(util.inspect(/foo(bar\n)?/gi), '/foo(bar\\n)?/gi'); | |||
assert.equal(util.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')), | |||
new Date('2010-02-14T12:48:40+01:00').toISOString()); | |||
assert.equal(util.inspect(new Date('')), (new Date('')).toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use assert.strictEqual()
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this simply:
assert.equal(util.inspect(new Date('')), 'Invalid Date');
there's no reason to create the second date object.
It's not a big deal because whoever lands this can fix it up but:
|
return ctx.stylize(value.toString(), 'date'); | ||
} else { | ||
return ctx.stylize(Date.prototype.toISOString.call(value), 'date'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a style nit so feel free to ignore...
return ctx.stylize(Number.isNaN(value.getTime()) ?
value.toString() :
Date.prototype.toISOString.call(value),
'date');
... would help eliminate some minor code duplication
semver-major because of the change in error handling (this eliminates a throw). |
This restores the pre-v6.0.0 behaviour and probably aligns much more with user expectations than the current behaviour, so I would actually say it’s a bugfix. Otherwise, this means that no object containing an invalid |
+1 to bug fix. |
Works for me! |
@cjihrig how should I fix branch and comment now in better way? |
Github doesn't allow you to target a new branch once a PR is made. However, To change your commit message, you can run |
@cjihrig Done |
LGTM once the comment about using |
Prevent util.inspect of throwing on date object with invalid date value. It changed to output result of toString method call.
LGTM. Thanks for the notification @jasnell |
LGTM. Running CI one more time https://ci.nodejs.org/job/node-test-pull-request/2559/ |
@cjihrig what's next? Will PR be accepted? |
@rumkin Thanks for commenting here again, sometimes things like this get a little lost. This LGTM and I’m landing it now. |
Prevent util.inspect of throwing on date object with invalid date value. It changed to output result of toString method call. PR-URL: #6504 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Landed in 9c33e0e. Thanks! |
Prevent util.inspect of throwing on date object with invalid date value. It changed to output result of toString method call. PR-URL: #6504 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
@nodejs/lts is this something we want to backport? |
@thealphanerd Just fyi, this was prompted by a change that came with the v8 changes in v6.0.0 and should be a no-op in the previous versions. |
Checklist
Description of change
util.inspect produces default string value for invalid date instead of throwing RangeError.