Skip to content

Commit

Permalink
fix: allow escape sequence in regexp class
Browse files Browse the repository at this point in the history
  • Loading branch information
iorate committed Aug 25, 2024
1 parent 18af182 commit 1a40a1f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/scripts/ruleset/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/scripts/ruleset/ruleset.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ expression[@isGroup=Expression] {
RegExp { "/" regExpPattern "/" regExpFlags? }
regExpPattern { (regExpEscape | "[" regExpClassContent* "]" | regExpContent)+ }
regExpEscape { "\\" ![\n] }
regExpClassContent { ![\]\\\n] }
regExpClassContent { ![\]\\\n] | "\\" ![\n] }
regExpContent { ![/\\[\n] }
regExpFlags { $[imsu]+ }

Expand Down
27 changes: 27 additions & 0 deletions src/scripts/ruleset/ruleset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,33 @@ test("Ruleset", async (t) => {
!ruleset.test({ url: "http://example.com/", title: "foo bar \\xA" }),
);
}
// Regular expression Literals
// Escape sequence in class characters
// https://github.com/iorate/ublacklist/issues/527
{
const ruleset = new Ruleset(String.raw`title=~/[\u3040-\u309F]/`);
assert.ok(
ruleset.test({
url: "http://example.com/",
title: "ひらがな",
}),
);
assert.ok(
!ruleset.test({
url: "http://example.com/",
title: "カタカナ",
}),
);
}
{
const ruleset = new Ruleset(String.raw`title=~/[\u3040-\u309G]/`);
assert.ok(
!ruleset.test({
url: "http://example.com/",
title: "ひらがな",
}),
);
}
});

await t.test("Complex expressions", () => {
Expand Down

0 comments on commit 1a40a1f

Please sign in to comment.