mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
url: fix isURL detection by checking path
Fixes: https://github.com/nodejs/node/issues/48921 PR-URL: https://github.com/nodejs/node/pull/48928 Fixes: https://github.com/getsentry/sentry-javascript/issues/8552 Fixes: https://github.com/request/request/issues/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>
This commit is contained in:
1 parent
771abcb5da
commit
60d614157b
2 files changed
+7
-2
No files matched your search
+2
-2
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
Reference in new issue
Block a user