Skip to content

Commit

Permalink
fix: Fix error where a lot of domains were not detected
Browse files Browse the repository at this point in the history
Fix separator logic in trie serializer

Affected domains:
- `niteroi.br / *.nom.br`
- `police.uk / *.sch.uk`
- `budejju.no / nes.buskerud.no`
- `hønefoss.no / os.hordaland.no`
- `molde.no / heroy.more-og-romsdal.no`
- `nordkapp.no / bo.nordland.no`
- `osterøy.no / valer.ostfold.no`
- `tananger.no / bo.telemark.no`
- `vestby.no / sande.vestfold.no`
- `haugesund.no / os.hedmark.no`

Fixes #64
  • Loading branch information
jpstevens authored and jhnns committed May 27, 2019
1 parent 1d1a24a commit fc80789
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/tries/serializeTrie.js
Expand Up @@ -42,14 +42,15 @@ function lineToString(line, i, arr) {
const prevLine = arr[i - 1];

indexOfDifference = findIndexOfDifference(line, prevLine);

if (indexOfDifference === -1) {
// Identical lines
return "";
}
if (indexOfDifference === 0) {
// line and prevLine are completely different
separatorFromPrev = SEPARATORS.RESET;
} else if (prevLine.length === line.length && indexOfDifference === line.length - 1) {
} else if (prevLine.length <= line.length && indexOfDifference === prevLine.length - 1) {
// only the last part of line and prevLine are different
separatorFromPrev = SEPARATORS.SAME;
} else if (indexOfDifference > prevLine.length - 1) {
Expand Down
8 changes: 8 additions & 0 deletions test/parseDomain.test.js
Expand Up @@ -172,6 +172,14 @@ describe("parseDomain(url)", () => {
});
});

it("should parse police.uk as tld", () => {
expect(parseDomain("example.police.uk")).to.eql({
subdomain: "",
domain: "example",
tld: "police.uk",
});
});

it("should also work with custom top-level domains passed as regexps", () => {
const options = {customTlds: /(\.local|localhost)$/};

Expand Down
2 changes: 1 addition & 1 deletion test/snapshots.test.js
Expand Up @@ -26,7 +26,7 @@ describe("snapshots", () => {
fs.writeFileSync(pathToParsePubSuffixListSnapshot, JSON.stringify(parsedList));
});
});
describe("serialieTrie()", () => {
describe("serializeTrie()", () => {
it("matches the approved snapshot", () => {
const parsedList = JSON.parse(fs.readFileSync(pathToParsePubSuffixListSnapshot, "utf8"));
const snapshot = JSON.parse(fs.readFileSync(pathToSerializeTrieSnapshot, "utf8"));
Expand Down
2 changes: 1 addition & 1 deletion test/snapshots/serializeTrie.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/tries/serializeTrie.test.js
Expand Up @@ -78,6 +78,7 @@ describe("serializeTrie()", () => {
[["pl", "gov.pl", "ap.gov.pl", "net.pl"], "pl>gov>ap<net"],
[["pl", "gov.pl", "ap.gov.pl", "uk", "ac.uk", "co.uk"], "pl>gov>ap|uk>ac,co"],
[["jp", "岐阜.jp", "静岡.jp", "موقع"], "jp>岐阜,静岡|موقع"],
[["uk", "ac.uk", "police.uk", "*.sch.uk"], "uk>ac,police,sch>*"],
].forEach(args => {
const parsedList = args[0];
const expectedString = args[1];
Expand Down

0 comments on commit fc80789

Please sign in to comment.