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 {
13
13
IteratorPrototype,
14
14
Number,
15
15
ObjectDefineProperties,
16
+ ObjectPrototypeHasOwnProperty,
16
17
ObjectSetPrototypeOf,
17
18
ReflectGetOwnPropertyDescriptor,
18
19
ReflectOwnKeys,
@@ -692,11 +693,14 @@ ObjectDefineProperties(URLSearchParams.prototype, {
692
693
*
693
694
* We use `href` and `protocol` as they are the only properties that are
694
695
* 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.
695
699
* @param {* } self
696
700
* @returns {self is URL }
697
701
*/
698
702
function isURL ( self ) {
699
- return Boolean ( self ?. href && self . protocol ) ;
703
+ return Boolean ( self ?. href && self . protocol && ! ObjectPrototypeHasOwnProperty ( self . auth ) ) ;
700
704
}
701
705
702
706
class 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