Skip to content

Commit cce6a1d

Browse files
Zhangdroidpluris
authored and
pluris
committed
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 6818d71 commit cce6a1d

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
@@ -753,13 +753,13 @@ ObjectDefineProperties(URLSearchParams.prototype, {
753753
* We use `href` and `protocol` as they are the only properties that are
754754
* easy to retrieve and calculate due to the lazy nature of the getters.
755755
*
756-
* We check for auth attribute to distinguish legacy url instance with
756+
* We check for `auth` and `path` attribute to distinguish legacy url instance with
757757
* WHATWG URL instance.
758758
* @param {*} self
759759
* @returns {self is URL}
760760
*/
761761
function isURL(self) {
762-
return Boolean(self?.href && self.protocol && self.auth === undefined);
762+
return Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined);
763763
}
764764

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