Skip to content

Commit

Permalink
Normalise initiator domains
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Jan 4, 2024
1 parent 0c072b3 commit bf1ab13
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
14 changes: 13 additions & 1 deletion src/converters/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function normalizeFilter(filter) {
});

// by default easylist syntax is case-insensitve
if (!params.find(p => p === 'match-case')) {
if (!params.find((p) => p === 'match-case')) {
front = front.toLowerCase();
}

Expand Down Expand Up @@ -49,5 +49,17 @@ export function normalizeRule(rule) {
) {
newRule.condition.regexFilter = `/${newRule.condition.regexFilter}/`;
}

if (newRule.condition && newRule.condition.excludedDomains) {
newRule.condition.excludedInitiatorDomains =
newRule.condition.excludedDomains;
delete newRule.condition.excludedDomains;
}

if (newRule.condition && newRule.condition.domains) {
newRule.condition.initiatorDomains = newRule.condition.domains;
delete newRule.condition.domains;
}

return newRule;
}
2 changes: 1 addition & 1 deletion test/unit/converters/abp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('abp converter', () => {
},
condition: {
domainType: "thirdParty",
domains: [
initiatorDomains: [
"x.z"
],
isUrlFilterCaseSensitive: false,
Expand Down
25 changes: 24 additions & 1 deletion test/unit/converters/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ describe('normalizeRule', () => {
})
})


it('wraps regex rules in //', () => {
expect(normalizeRule({
condition: {
Expand All @@ -98,4 +97,28 @@ describe('normalizeRule', () => {
},
});
});

it('replaces domains with initiatorDomains', () => {
expect(normalizeRule({
condition: {
domains: ['test'],
},
})).toEqual({
condition: {
initiatorDomains: ['test'],
},
});
});

it('replaces excludedDomains with excludedInitiatorDomains', () => {
expect(normalizeRule({
condition: {
excludedDomains: ['test'],
},
})).toEqual({
condition: {
excludedInitiatorDomains: ['test'],
},
});
});
});
10 changes: 0 additions & 10 deletions test/unit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ function normalize(rule) {
}
delete rule.priority;
delete rule.id;
if (rule.condition) {
if (rule.condition.excludedDomains) {
rule.condition.excludedInitiatorDomains = rule.condition.excludedDomains;
delete rule.condition.excludedDomains;
}
if (rule.condition.domains) {
rule.condition.initiatorDomains = rule.condition.domains;
delete rule.condition.domains;
}
}
return rule;
}

Expand Down

0 comments on commit bf1ab13

Please sign in to comment.