Skip to content

Commit

Permalink
Extended tests and fix in wildcard matching from tldts-experimental (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
remusao authored Apr 1, 2023
1 parent bc3d527 commit 5aab0ba
Show file tree
Hide file tree
Showing 4 changed files with 20,120 additions and 6 deletions.
14 changes: 10 additions & 4 deletions packages/tldts-experimental/src/packed-hashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,16 @@ export default function suffixLookup(
// was *.com, we would have stored only 'com' in the packed structure and we
// need to take one extra label on the left.
if ((matchKind & Result.WILDCARD_MATCH) !== 0) {
out.publicSuffix =
matchLabels >= numberOfHashes
? hostname
: hostname.slice(BUFFER[((matchLabels - 1) << 1) + 1]);
if (matchLabels < numberOfHashes) {
out.publicSuffix = hostname.slice(BUFFER[((matchLabels - 1) << 1) + 1]);
return;
}

const parts = hostname.split('.');
while (parts.length > matchLabels) {
parts.shift();
}
out.publicSuffix = parts.join('.');
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tldts-experimental/test/publicsuffix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { publicSuffixListTests } from 'tldts-tests';

import * as tld from '../index';

describe('tldts classic', () => {
describe('tldts experimental', () => {
publicSuffixListTests(tld.getDomain);
});
2 changes: 1 addition & 1 deletion packages/tldts-experimental/test/tld.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { tldtsTests } from 'tldts-tests';

import * as tld from '../index';

describe('tldts classic', () => {
describe('tldts experimental', () => {
tldtsTests(tld);
});
Loading

0 comments on commit 5aab0ba

Please sign in to comment.