-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
url: improve isURL detection
#47886
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 isURL detection
#47886
Conversation
|
Review requested:
|
|
Can we add a test that checks without 'use strict';
const common = require('../common');
if (!common.hasCrypto) { common.skip('missing crypto'); }
const assert = require('assert');
const opt = require('url').parse('https://httpbin.org/get');
require('https')
.request(
{ ...opt, path: opt.path + '?A=B' },
(s) => s.once('data',
(d) => assert.ok(d.toString('UTF8').includes('https://httpbin.org/get?A=B'))))
.end();This will test the behavior the user experiences rather than internal implementation details. It can probably be improved (e.g., to aggregate the data chunks rather than assume it will all be in the first chunk), but you get the idea. |
|
Of course, @Trott can you block the pull request to avoid accidentaly merging this pr? |
|
(Removing |
And now putting it back because we can always add the test in a subsequent PR. |
| * We use `href` and `protocol` as they are the only properties that are | ||
| * easy to retrieve and calculate due to the lazy nature of the getters. | ||
| * | ||
| * We check for auth attribute to distinguish legacy url instance with |
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.
| * We check for auth attribute to distinguish legacy url instance with | |
| * We check for auth attribute to distinguish legacy URL instance with |
For consistency.
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 is the name of the WHATWG URL object. Perhaps to avoid confusion, it should be urlObject here to be consistent with https://nodejs.org/dist/latest-v20.x/docs/api/url.html#legacy-urlobject?
| * We check for auth attribute to distinguish legacy url instance with | |
| * We check for auth attribute to distinguish legacy urlObject instance with |
Trott
left a comment
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.
Needs a public API test.
Sure. Done. |
|
My test suggestion is not great as it depends on the behavior of an external service. I'm going to unblock this. We can always add another test later. |
|
Landed in 528aaca |
PR-URL: #47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#47886 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs/node#47886 Backport-PR-URL: nodejs/node#50105 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs/node#47886 Backport-PR-URL: nodejs/node#50105 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Previously we were checking for
protocolandoriginattributes, but due to the lazy-loading nature of Ada 2.0 withurl_aggregatorwe shifted from checking fororigin. This was also breaking the detection of the legacy URL parse function. This PR fixes that in the least impactful way possible, by checking ifauthproperty is defined.Fixes #47624
cc @nodejs/url @Trott