Skip to content

Commit 5d2a08a

Browse files
ZhangdroidUlisesGascon
authored andcommitted
url: fix isURL detection by checking path
Fixes: nodejs#48921 PR-URL: nodejs#48928 Fixes: getsentry/sentry-javascript#8552 Fixes: request/request#3458 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
1 parent 63d2466 commit 5d2a08a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/internal/url.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -747,13 +747,13 @@ ObjectDefineProperties(URLSearchParams.prototype, {
747747
* We use `href` and `protocol` as they are the only properties that are
748748
* easy to retrieve and calculate due to the lazy nature of the getters.
749749
*
750-
* We check for auth attribute to distinguish legacy url instance with
750+
* We check for `auth` and `path` attribute to distinguish legacy url instance with
751751
* WHATWG URL instance.
752752
* @param {*} self
753753
* @returns {self is URL}
754754
*/
755755
function isURL(self) {
756-
return Boolean(self?.href && self.protocol && self.auth === undefined);
756+
return Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined);
757757
}
758758

759759
class URL {

test/parallel/test-url-is-url.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ const { isURL } = require('internal/url');
99

1010
assert.strictEqual(isURL(new URL('https://www.nodejs.org')), true);
1111
assert.strictEqual(isURL(parse('https://www.nodejs.org')), false);
12+
assert.strictEqual(isURL({
13+
href: 'https://www.nodejs.org',
14+
protocol: 'https:',
15+
path: '/',
16+
}), false);

0 commit comments

Comments
 (0)