tldts-experimental 7.5.0 → 7.5.1

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
@@ -823,9 +823,9 @@ function extraSuffixLookup(hostname, options, isException, out) {
823
823
  }
824
824
  continue;
825
825
  }
826
- // `*.p` also matches `p`, else one more label (possibly empty: '.p').
827
- if (wildcard && start !== 0) {
828
- start = start === 1 ? 0 : hostname.lastIndexOf('.', start - 2) + 1;
826
+ // `*.p` also matches `p`, else one more non-empty label.
827
+ if (wildcard && start > 1 && hostname.charCodeAt(start - 2) !== 46) {
828
+ start = hostname.lastIndexOf('.', start - 2) + 1;
829
829
  }
830
830
  if (start < rule) {
831
831
  rule = start;
@@ -939,7 +939,12 @@ function parseImpl(url, step, suffixLookup, partialOptions, result) {
939
939
  // extractHostname returned `url` unchanged (same reference).
940
940
  let urlIsValid = false;
941
941
  if (!options.extractHostname) {
942
- result.hostname = url;
942
+ // Trim trailing dots as extractHostname does (`new URL()` keeps them).
943
+ let end = url.length;
944
+ while (end > 1 && url.charCodeAt(end - 1) === 46 /* '.' */) {
945
+ end -= 1;
946
+ }
947
+ result.hostname = end === url.length ? url : url.slice(0, end);
943
948
  }
944
949
  else if (options.mixedInputs) {
945
950
  urlIsValid = isValidHostname(url);
@@ -1248,6 +1253,12 @@ function suffixLookup(hostname, options, out) {
1248
1253
  // important to make sure that we always keep the longest match if there
1249
1254
  // are both a wildcard and a normal rule matching).
1250
1255
  if (match !== 0 /* Result.NO_MATCH */) {
1256
+ // '*' never matches an empty label ('.S', '..S'): `*.S` then only
1257
+ // implies `S`.
1258
+ if ((match & 16 /* Result.WILDCARD_MATCH */) !== 0 &&
1259
+ (labelStart === 1 || hostname.charCodeAt(labelStart - 2) === 46)) {
1260
+ match = (match & -17 /* Result.WILDCARD_MATCH */) | 8 /* Result.NORMAL_MATCH */;
1261
+ }
1251
1262
  matchKind = match;
1252
1263
  matchLabels = label + ((match & 16 /* Result.WILDCARD_MATCH */) !== 0 ? 2 : 1);
1253
1264
  matchIndex = labelStart;