File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const {
1313 IteratorPrototype,
1414 Number,
1515 ObjectDefineProperties,
16+ ObjectPrototypeHasOwnProperty,
1617 ObjectSetPrototypeOf,
1718 ReflectGetOwnPropertyDescriptor,
1819 ReflectOwnKeys,
@@ -692,11 +693,14 @@ ObjectDefineProperties(URLSearchParams.prototype, {
692693 *
693694 * We use `href` and `protocol` as they are the only properties that are
694695 * easy to retrieve and calculate due to the lazy nature of the getters.
696+ *
697+ * We check for auth attribute to distinguish legacy url instance with
698+ * WHATWG URL instance.
695699 * @param {* } self
696700 * @returns {self is URL }
697701 */
698702function isURL ( self ) {
699- return Boolean ( self ?. href && self . protocol ) ;
703+ return Boolean ( self ?. href && self . protocol && ! ObjectPrototypeHasOwnProperty ( self . auth ) ) ;
700704}
701705
702706class URL {
Original file line number Diff line number Diff line change 1+ // Flags: --expose-internals
2+ 'use strict' ;
3+
4+ require ( '../common' ) ;
5+
6+ const { URL , parse } = require ( 'url' ) ;
7+ const assert = require ( 'assert' ) ;
8+ const { isURL } = require ( 'internal/url' ) ;
9+
10+ assert . strictEqual ( isURL ( new URL ( 'https://www.nodejs.org' ) ) , true ) ;
11+ assert . strictEqual ( isURL ( parse ( 'https://www.nodejs.org' ) ) , false ) ;
You can’t perform that action at this time.
0 commit comments