tldts 7.4.27 → 7.4.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -229,7 +229,7 @@ function extractHostname(url, urlIsValidHostname, validate = false) {
229
229
  start += 2;
230
230
  }
231
231
  else {
232
- const indexOfProtocol = url.indexOf(':/', start);
232
+ let indexOfProtocol = url.indexOf(':/', start);
233
233
  if (indexOfProtocol !== -1) {
234
234
  // "scheme://…". Classify the scheme, then position `start` at the host.
235
235
  const special = getSpecialScheme(url, start, indexOfProtocol);
@@ -272,25 +272,40 @@ function extractHostname(url, urlIsValidHostname, validate = false) {
272
272
  code === 13 /* CR */) {
273
273
  return extractHostname(url.replace(CONTROL_CHARS, ''), urlIsValidHostname, validate);
274
274
  }
275
- return null;
275
+ // A '/', '\', '?' or '#' first puts this ':/' in a path, query or
276
+ // fragment ("a.com/r?u=https://x"): re-read the input without it.
277
+ for (let j = i; j < indexOfProtocol; j += 1) {
278
+ const c = url.charCodeAt(j);
279
+ if (c === 47 || c === 92 || c === 63 || c === 35) {
280
+ indexOfProtocol = -1;
281
+ break;
282
+ }
283
+ }
284
+ if (indexOfProtocol !== -1) {
285
+ return null;
286
+ }
287
+ break;
276
288
  }
277
289
  }
278
- // A non-special scheme has an authority only after "//" (else it is an
279
- // opaque path with no host). `indexOf(':/')` already gave the first '/'.
280
- if (url.charCodeAt(indexOfProtocol + 2) === 47 /* '/' */) {
281
- isSpecial = false;
282
- start = indexOfProtocol + 3;
283
- }
284
- else {
285
- return null;
290
+ if (indexOfProtocol !== -1) {
291
+ // A non-special scheme has an authority only after "//" (else it is
292
+ // an opaque path with no host). `indexOf(':/')` already gave the
293
+ // first '/'.
294
+ if (url.charCodeAt(indexOfProtocol + 2) === 47 /* '/' */) {
295
+ isSpecial = false;
296
+ start = indexOfProtocol + 3;
297
+ }
298
+ else {
299
+ return null;
300
+ }
286
301
  }
287
302
  }
288
303
  }
289
- else if (url.charCodeAt(start) !== 91 /* '[' */) {
290
- // Cold path: no scheme "://", and not a bare IPv6 literal (whose first
291
- // ':' would otherwise look like a scheme separator; "[…]" falls through
292
- // to the ipv6 handling below). May be a bare host, a host:port, a
293
- // user@host, a slash-less special scheme ("https:host"), or an opaque
304
+ if (indexOfProtocol === -1 && url.charCodeAt(start) !== 91 /* '[' */) {
305
+ // Cold path: no "scheme://" prefix, and not a bare IPv6 literal (whose
306
+ // first ':' would otherwise look like a scheme separator; "[…]" falls
307
+ // through to the ipv6 handling below). May be a bare host, a host:port,
308
+ // a user@host, a slash-less special scheme ("https:host"), or an opaque
294
309
  // URI ("mailto:", "tel:", "urn:…").
295
310
  let indexOfColon = -1;
296
311
  for (let i = start; i < end; i += 1) {
@@ -341,7 +356,7 @@ function extractHostname(url, urlIsValidHostname, validate = false) {
341
356
  if (!allDigits) {
342
357
  const special = getSpecialScheme(url, start, indexOfColon);
343
358
  if (special === 0) {
344
- // No "://" anywhere on the cold path and not a special scheme.
359
+ // No "scheme://" on the cold path and not a special scheme.
345
360
  // A second ':' before the host's end marks a bare, unbracketed
346
361
  // IPv6 literal ("2a01:e35::1"): fall through and let the host
347
362
  // loop + isIp classify it. Without one this is an opaque path