Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix error where a lot of domains were not detected #65

Merged
merged 2 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/tries/serializeTrie.js
Original file line number Diff line number Diff line change
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) {
Copy link
Member

@jhnns jhnns May 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the whole length check is not necessary or too strict. We should just compare 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
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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