@@ -133,8 +133,8 @@ assert.strictEqual(url.searchParams, oldParams);
133
133
134
134
// Test urlToOptions
135
135
{
136
- const opts =
137
- urlToOptions ( new URL ( 'http://user:pass@foo.bar.com:21/aaa/zzz?l=24#test' ) ) ;
136
+ const urlObj = new URL ( 'http://user:pass@foo.bar.com:21/aaa/zzz?l=24#test' ) ;
137
+ const opts = urlToOptions ( urlObj ) ;
138
138
assert . strictEqual ( opts instanceof URL , false ) ;
139
139
assert . strictEqual ( opts . protocol , 'http:' ) ;
140
140
assert . strictEqual ( opts . auth , 'user:pass' ) ;
@@ -147,6 +147,23 @@ assert.strictEqual(url.searchParams, oldParams);
147
147
148
148
const { hostname } = urlToOptions ( new URL ( 'http://[::1]:21' ) ) ;
149
149
assert . strictEqual ( hostname , '::1' ) ;
150
+
151
+ // If a WHATWG URL object is copied, it is possible that the resulting copy
152
+ // contains the Symbols that Node uses for brand checking, but not the data
153
+ // properties, which are getters. Verify that urlToOptions() can handle such
154
+ // a case.
155
+ const copiedUrlObj = Object . assign ( { } , urlObj ) ;
156
+ const copiedOpts = urlToOptions ( copiedUrlObj ) ;
157
+ assert . strictEqual ( copiedOpts instanceof URL , false ) ;
158
+ assert . strictEqual ( copiedOpts . protocol , undefined ) ;
159
+ assert . strictEqual ( copiedOpts . auth , undefined ) ;
160
+ assert . strictEqual ( copiedOpts . hostname , undefined ) ;
161
+ assert . strictEqual ( copiedOpts . port , NaN ) ;
162
+ assert . strictEqual ( copiedOpts . path , '' ) ;
163
+ assert . strictEqual ( copiedOpts . pathname , undefined ) ;
164
+ assert . strictEqual ( copiedOpts . search , undefined ) ;
165
+ assert . strictEqual ( copiedOpts . hash , undefined ) ;
166
+ assert . strictEqual ( copiedOpts . href , undefined ) ;
150
167
}
151
168
152
169
// Test special origins
0 commit comments