Skip to content

Commit fc80789

Browse files
jpstevensjhnns
authored andcommitted
fix: Fix error where a lot of domains were not detected
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
1 parent 1d1a24a commit fc80789

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

src/tries/serializeTrie.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ function lineToString(line, i, arr) {
4242
const prevLine = arr[i - 1];
4343

4444
indexOfDifference = findIndexOfDifference(line, prevLine);
45+
4546
if (indexOfDifference === -1) {
4647
// Identical lines
4748
return "";
4849
}
4950
if (indexOfDifference === 0) {
5051
// line and prevLine are completely different
5152
separatorFromPrev = SEPARATORS.RESET;
52-
} else if (prevLine.length === line.length && indexOfDifference === line.length - 1) {
53+
} else if (prevLine.length <= line.length && indexOfDifference === prevLine.length - 1) {
5354
// only the last part of line and prevLine are different
5455
separatorFromPrev = SEPARATORS.SAME;
5556
} else if (indexOfDifference > prevLine.length - 1) {

test/parseDomain.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ describe("parseDomain(url)", () => {
172172
});
173173
});
174174

175+
it("should parse police.uk as tld", () => {
176+
expect(parseDomain("example.police.uk")).to.eql({
177+
subdomain: "",
178+
domain: "example",
179+
tld: "police.uk",
180+
});
181+
});
182+
175183
it("should also work with custom top-level domains passed as regexps", () => {
176184
const options = {customTlds: /(\.local|localhost)$/};
177185

test/snapshots.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("snapshots", () => {
2626
fs.writeFileSync(pathToParsePubSuffixListSnapshot, JSON.stringify(parsedList));
2727
});
2828
});
29-
describe("serialieTrie()", () => {
29+
describe("serializeTrie()", () => {
3030
it("matches the approved snapshot", () => {
3131
const parsedList = JSON.parse(fs.readFileSync(pathToParsePubSuffixListSnapshot, "utf8"));
3232
const snapshot = JSON.parse(fs.readFileSync(pathToSerializeTrieSnapshot, "utf8"));

test/snapshots/serializeTrie.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

test/tries/serializeTrie.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe("serializeTrie()", () => {
7878
[["pl", "gov.pl", "ap.gov.pl", "net.pl"], "pl>gov>ap<net"],
7979
[["pl", "gov.pl", "ap.gov.pl", "uk", "ac.uk", "co.uk"], "pl>gov>ap|uk>ac,co"],
8080
[["jp", "岐阜.jp", "静岡.jp", "موقع"], "jp>岐阜,静岡|موقع"],
81+
[["uk", "ac.uk", "police.uk", "*.sch.uk"], "uk>ac,police,sch>*"],
8182
].forEach(args => {
8283
const parsedList = args[0];
8384
const expectedString = args[1];

0 commit comments

Comments
 (0)