Skip to content
This repository was archived by the owner on May 9, 2021. It is now read-only.

Commit 3be287e

Browse files
author
Chan Chak Shing
authored
Fix a bug with empty domain groups and missing files (#31)
* Fix a bug with empty domain groups, follow-up #29 * Fix bug with empty domain groups and missing files
1 parent 3708fe2 commit 3be287e

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

script/libs/splitDomainsByTlds.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
*/
77
function splitDomainsByTlds(domains) {
88
let retval = [domains];
9-
for (let tldCounts = 1; tldCounts < 2; ++tldCounts) {
9+
for (let tldCounts = 1; tldCounts < 3; ++tldCounts) {
1010
let tlds = domains.map((domain) =>
1111
domain.split(".").reverse().slice(0, tldCounts).reverse().join(".")
1212
);
1313

1414
// remove possible duplicates
1515
tlds = Array.from(new Set(tlds));
16+
let tmp = tlds
17+
.map((tld) =>
18+
domains.filter((domain) => domain.endsWith(`.${tld}`) || domain === tld)
19+
)
20+
.filter((arr) => arr.length > 0);
1621

17-
if (tlds.length > 1) {
18-
retval = tlds.map((tld) =>
19-
domains.filter((domain) => domain.endsWith(`.${tld}`))
20-
);
22+
if (tmp.length > 1) {
23+
retval = tmp;
2124
break;
2225
}
2326
}

script/ruleset-update.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ if (process.argv.length <= 2) {
1818
}
1919

2020
// create a backup of the input FILE if it does not exist
21-
// path.normalize mess up files with underscore in their names
22-
const filename = process.argv[2];
21+
const filename = path.normalize(process.argv[2]);
2322
const backupFilename = filename + ".bak";
2423
if (!fs.existsSync(backupFilename)) {
2524
fs.copyFileSync(filename, backupFilename);
@@ -64,11 +63,11 @@ for (const domains of domainGroups) {
6463
const command = rawCommandParts.filter((part) => part != null).join(" ");
6564
child_process.execSync(command);
6665

67-
// remove the original file if neccessary
68-
if (domainGroups.length > 1) {
69-
fs.unlinkSync(filename);
70-
}
71-
7266
// remove temporary file
7367
fs.unlinkSync(tmpFilename);
7468
}
69+
70+
// remove the original file if neccessary
71+
if (domainGroups.length > 1) {
72+
fs.unlinkSync(filename);
73+
}

0 commit comments

Comments
 (0)