-
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
url: improve WHATWG URL inspection #12253
Conversation
lib/internal/url.js
Outdated
port: this.port, | ||
pathname: this.pathname, | ||
search: this.search, | ||
searchParams: this.searchParams, |
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.
Shouldn't this be this[searchParams]
since searchParams
is a Symbol
and not a regular property name?
Additionally, I think it's very misleading to be representing the searchParams
as a regular property when it cannot be accessed as such.
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.
url.searchParams
is a property one can access: https://nodejs.org/api/url.html#url_url_searchparams
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.
Ah ok, I missed that.
lib/internal/url.js
Outdated
return ret; | ||
|
||
return util.inspect(obj, opts).replace(/^URLTemp/, | ||
() => this.constructor.name); |
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.
Couldn't this be simplified to just be 'URL'
?
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 wanted to allow subclassing. For example, with this PR and
class MyURL extends URL {}
inspecting new MyURL('...')
will show MyURL
instead URL
.
lib/internal/url.js
Outdated
protocol: this.protocol, | ||
username: this.username, | ||
password: (opts.showHidden || ctx.password == null) ? | ||
this.password : '--------', |
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.
This might be confusing/unexpected behavior for some... Why hide it at all? There does not seem to be a precedent for this AFAICT. For example the browser seems to show the password
value every time when inspecting it.
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.
/cc @jasnell
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.
This was me just being paranoid ;-) ... I'm fine with showing the password here.
lib/internal/url.js
Outdated
ret += '}'; | ||
return ret; | ||
|
||
return util.inspect(obj, opts).replace(/^URLTemp/, |
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.
This replace()
can be avoided by simply doing var URL = function() {};
at the top of the function here and then simply using new URL()
instead of new URLTemp()
.
lib/internal/url.js
Outdated
if (typeof depth === 'number' && depth < 0) | ||
return opts.stylize('[Object]', 'special'); | ||
|
||
const obj = Object.assign(new URLTemp(), { |
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 think we should avoid Object.assign()
, especially when we're already using a custom/"fake" constructor which could easily assign its own appropriate values in its constructor (e.g. just pass this
to the constructor).
Did you benchmark the |
port: '8080', | ||
pathname: '/path/name/', | ||
search: '?que=ry', | ||
searchParams: URLSearchParams { 'que' => 'ry' }, |
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't really say that I'm a fan of the use of =>
here instead of a :
.
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.
That is to be consistent with the inspection output of Map
, plus it's weird to write
{ query: 'value1',
query: 'value2' }
with object literal syntax when it doesn't really work.
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.
Well, multiple values could be shown together as an array?
{ query: [ 'value1', 'value2' ] }
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.
@mscdex that'd remove the order of queries.
Landed in 2841f47 |
PR-URL: #12253 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
searchParams
!)depth
this
is not an actual URL[context]
ifshowHidden
is trueBefore:
After:
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
url