| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0080350 commit 0017855
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1257,13 +1257,13 @@ function domainToUnicode(domain) { | |||
| 1257 | 1257 | function urlToOptions(url) { | |
| 1258 | 1258 | var options = { | |
| 1259 | 1259 | protocol: url.protocol, | |
| 1260 | - hostname: url.hostname.startsWith('[') ? | ||
| 1260 | + hostname: typeof url.hostname === 'string' && url.hostname.startsWith('[') ? | ||
| 1261 | 1261 | url.hostname.slice(1, -1) : | |
| 1262 | 1262 | url.hostname, | |
| 1263 | 1263 | hash: url.hash, | |
| 1264 | 1264 | search: url.search, | |
| 1265 | 1265 | pathname: url.pathname, | |
| 1266 | - path: `${url.pathname}${url.search}`, | ||
| 1266 | + path: `${url.pathname || ''}${url.search || ''}`, | ||
| 1267 | 1267 | href: url.href | |
| 1268 | 1268 | }; | |
| 1269 | 1269 | if (url.port !== '') { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments