Skip to content

Commit

Permalink
Merge pull request #530 from iorate/allow-regexp-class-escape-sequence
Browse files Browse the repository at this point in the history
fix: allow escape sequence in regexp class
  • Loading branch information
iorate authored Aug 25, 2024
2 parents 9730a7d + 1a40a1f commit 402cb00
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 402cb00

Please sign in to comment.