Skip to content

Commit

Permalink
Fix rule to block URL from start only
Browse files Browse the repository at this point in the history
  • Loading branch information
penge committed Aug 25, 2023
1 parent ec6e806 commit a668c15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/helpers/__tests__/find-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ test("findRule()", () => {
path: "youtube.com",
type: "block",
});

expect(findRule("https://www.nginx.com/", ["x.com"])).toBe(undefined);
expect(findRule("https://x.com/", ["nginx.com"])).toBe(undefined);
});
2 changes: 1 addition & 1 deletion src/helpers/find-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import makeRules, { Rule } from "./make-rules";
export default (url: string, blocked: string[]): Rule | undefined => {
const normalizedUrl = normalizeUrl(url);
const rules = makeRules(blocked);
const foundRule = rules.find((rule) => normalizedUrl.startsWith(rule.path) || normalizedUrl.endsWith(rule.path));
const foundRule = rules.find((rule) => normalizedUrl.startsWith(rule.path));
return foundRule;
};

0 comments on commit a668c15

Please sign in to comment.