@@ -133,8 +133,8 @@ assert.strictEqual(url.searchParams, oldParams);
133133
134134// Test urlToOptions
135135{
136- const opts =
137- urlToOptions ( new URL ( 'http://user:[email protected] :21/aaa/zzz?l=24#test' ) ) ; 136+ const urlObj = new URL ( 'http://user:[email protected] :21/aaa/zzz?l=24#test' ) ; 137+ const opts = urlToOptions ( urlObj ) ;
138138 assert . strictEqual ( opts instanceof URL , false ) ;
139139 assert . strictEqual ( opts . protocol , 'http:' ) ;
140140 assert . strictEqual ( opts . auth , 'user:pass' ) ;
@@ -147,6 +147,23 @@ assert.strictEqual(url.searchParams, oldParams);
147147
148148 const { hostname } = urlToOptions ( new URL ( 'http://[::1]:21' ) ) ;
149149 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 ) ;
150167}
151168
152169// Test special origins
0 commit comments