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: fix isURL detection by checking path #48928

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,13 +753,13 @@ 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
* We check for `auth` and `path` attribute to distinguish legacy url instance with
* WHATWG URL instance.
* @param {*} self
* @returns {self is URL}
*/
function isURL(self) {
return Boolean(self?.href && self.protocol && self.auth === undefined);
return Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined);
Copy link
Contributor Author

@Zhangdroid Zhangdroid Jul 26, 2023

Choose a reason for hiding this comment

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

TBH, I don't think this is the ideal way to fix the issue #48921 , but since path is an attribute in legacy URL object instance, and another issue has been fixed in same way: #47886 I think this fix maybe fine. If you have a better way, please let me know.

}

class URL {
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-url-is-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ const { isURL } = require('internal/url');

assert.strictEqual(isURL(new URL('https://www.nodejs.org')), true);
assert.strictEqual(isURL(parse('https://www.nodejs.org')), false);
assert.strictEqual(isURL({
href: 'https://www.nodejs.org',
protocol: 'https:',
path: '/',
}), false);
Loading