Fix invalid date output with util.inspect#6504
Conversation
test/parallel/test-util-inspect.js
Outdated
There was a problem hiding this comment.
Can you use assert.strictEqual() here.
There was a problem hiding this comment.
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:
|
lib/util.js
Outdated
There was a problem hiding this comment.
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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
|
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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
|
@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.