Skip to content

Commit

Permalink
url: fix isURL detection by checking path
Browse files Browse the repository at this point in the history
Fixes: #48921
PR-URL: #48928
Fixes: getsentry/sentry-javascript#8552
Fixes: request/request#3458
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
  • Loading branch information
Zhangdroid authored and RafaelGSS committed Aug 17, 2023
1 parent 771abcb commit 60d6141
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,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);
}

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);

0 comments on commit 60d6141

Please sign in to comment.