Skip to content

Commit 52b231f

Browse files
authored
fix: Do not escape backslashes during rules:if evaluation (#1303)
1 parent b1cc2ed commit 52b231f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class Utils {
203203
// Expand all variables
204204
evalStr = this.expandTextWith(evalStr, {
205205
unescape: JSON.stringify("$"),
206-
variable: (name) => JSON.stringify(envs[name] ?? null),
206+
variable: (name) => JSON.stringify(envs[name] ?? null).replaceAll("\\\\", "\\"),
207207
});
208208

209209
// Convert =~ to match function

tests/rules.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ test("Complex parentheses junctions regex fail - case insensitive", () => {
238238
expect(val).toBe(false);
239239
});
240240

241+
test("Regex with escape characters from variable", () => {
242+
const ruleIf = "$TAG =~ $TAG_REGEX";
243+
const val = Utils.evaluateRuleIf(ruleIf, {TAG: "prefix/1.0.0", TAG_REGEX: "/^prefix\\/.+/"});
244+
expect(val).toBe(true);
245+
});
246+
241247
test("https://github.com/firecow/gitlab-ci-local/issues/350", () => {
242248
let rules, rulesResult, variables;
243249
rules = [

0 commit comments

Comments
 (0)