Skip to content
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

Merged
merged 1 commit into from
May 7, 2023
Merged

url: improve isURL detection #47886

merged 1 commit into from
May 7, 2023

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented May 5, 2023

Previously we were checking for protocol and origin attributes, but due to the lazy-loading nature of Ada 2.0 with url_aggregator we shifted from checking for origin. This was also breaking the detection of the legacy URL parse function. This PR fixes that in the least impactful way possible, by checking if auth property is defined.

Fixes #47624

cc @nodejs/url @Trott

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/url

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels May 5, 2023
lib/internal/url.js Outdated Show resolved Hide resolved
@anonrig anonrig requested a review from TimothyGu May 5, 2023 19:51
@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels May 5, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2023
@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label May 6, 2023
@Trott
Copy link
Member

Trott commented May 6, 2023

Can we add a test that checks without --expose-internals? Something like this would work, I think:

'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.

@anonrig
Copy link
Member Author

anonrig commented May 6, 2023

Of course, @Trott can you block the pull request to avoid accidentaly merging this pr?

@Trott Trott removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 6, 2023
@Trott
Copy link
Member

Trott commented May 6, 2023

(Removing commit queue label pending "do we need test that checks the public API/behavior" resolution.)

@Trott
Copy link
Member

Trott commented May 6, 2023

(Removing commit queue label pending "do we need test that checks the public API/behavior" resolution.)

And now putting it back because we can always add the test in a subsequent PR.

@Trott Trott added the commit-queue Add this label to land a pull request using GitHub Actions. label May 6, 2023
@@ -692,11 +692,14 @@ ObjectDefineProperties(URLSearchParams.prototype, {
*
* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* We check for auth attribute to distinguish legacy url instance with
* We check for auth attribute to distinguish legacy URL instance with

For consistency.

Copy link
Member

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?

Suggested change
* We check for auth attribute to distinguish legacy url instance with
* We check for auth attribute to distinguish legacy urlObject instance with

Copy link
Member

@Trott Trott left a 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.

@Trott
Copy link
Member

Trott commented May 6, 2023

Of course, @Trott can you block the pull request to avoid accidentaly merging this pr?

Sure. Done.

@Trott Trott removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 6, 2023
@Trott
Copy link
Member

Trott commented May 6, 2023

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.

@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 7, 2023
@nodejs-github-bot nodejs-github-bot merged commit 528aaca into main May 7, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 528aaca

@nodejs-github-bot nodejs-github-bot deleted the url-fix-detection branch May 7, 2023 19:41
targos pushed a commit that referenced this pull request May 12, 2023
PR-URL: #47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
anonrig added a commit to anonrig/node that referenced this pull request Jun 5, 2023
PR-URL: nodejs#47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
anonrig added a commit to anonrig/node that referenced this pull request Jun 5, 2023
PR-URL: nodejs#47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
anonrig added a commit to anonrig/node that referenced this pull request Jun 5, 2023
PR-URL: nodejs#47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@anonrig anonrig added the backport-open-v18.x Indicate that the PR has an open backport. label Jun 5, 2023
anonrig added a commit to anonrig/node that referenced this pull request Jun 17, 2023
PR-URL: nodejs#47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
anonrig added a commit to anonrig/node that referenced this pull request Jun 23, 2023
PR-URL: nodejs#47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
anonrig added a commit to anonrig/node that referenced this pull request Jun 24, 2023
PR-URL: nodejs#47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
anonrig added a commit to anonrig/node that referenced this pull request Jun 24, 2023
PR-URL: nodejs#47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
aduh95 pushed a commit to aduh95/node that referenced this pull request Oct 9, 2023
PR-URL: nodejs#47886
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
targos pushed a commit that referenced this pull request Nov 27, 2023
PR-URL: #47886
Backport-PR-URL: #50105
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@richardlau richardlau added backported-to-v18.x PRs backported to the v18.x-staging branch. and removed backport-open-v18.x Indicate that the PR has an open backport. labels Mar 18, 2024
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#47886
Backport-PR-URL: nodejs/node#50105
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#47886
Backport-PR-URL: nodejs/node#50105
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backported-to-v18.x PRs backported to the v18.x-staging branch. needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undocumented behavior for handling options of http.request
7 participants