Skip to content

Commit ebafd63

Browse files
authored
fix: parsing of regex in rules:if clause (#1712)
1 parent 22d8dbf commit ebafd63

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class Utils {
238238

239239
// Scenario when RHS is a <regex>
240240
// https://regexr.com/85sjo
241-
const pattern1 = /\s*(?<operator>(?:=~)|(?:!~))\s*\/(?<rhs>.*?)\/(?<flags>[igmsuy]*)(\s|$|\))/g;
241+
const pattern1 = /\s*(?<operator>(?:=~)|(?:!~))\s*\/(?<rhs>.*?[^\\])\/(?<flags>[igmsuy]*)(\s|$|\))/g;
242242
evalStr = evalStr.replace(pattern1, (_, operator, rhs, flags, remainingTokens) => {
243243
let _operator;
244244
switch (operator) {

tests/rules-regex.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ const tests = [
114114
jsExpression: '("qwerty".matchRE2JS(RE2JS.compile("^perf_.*$", 0)) != null)',
115115
evalResult: false,
116116
},
117+
{
118+
rule: `"product-name/v0.0.0+build.0" =~ /^(?:product-name\\/)?v\\d+\\.\\d+\\.\\d+.*/`,
119+
jsExpression: "\"product-name/v0.0.0+build.0\".matchRE2JS(RE2JS.compile(\"^(?:product-name\\\\/)?v\\\\d+\\\\.\\\\d+\\\\.\\\\d+.*\", 0)) != null",
120+
evalResult: true,
121+
},
117122
];
118123
/* eslint-enable @stylistic/ts/quotes */
119124

0 commit comments

Comments
 (0)