diff --git a/src/utils.ts b/src/utils.ts index eff62d774..19b6ad5fc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -218,7 +218,7 @@ export class Utils { default: throw operator; } - return `.match(${rhs}${flags})${remainingTokens} ${_operator} null`; + return `.match(${rhs}${flags})${remainingTokens} ${_operator} null `; }); // Scenario when RHS is surrounded by double-quotes @@ -250,8 +250,10 @@ Refer to https://docs.gitlab.com/ee/ci/jobs/job_rules.html#unexpected-behavior-f }); // Convert all null.match functions to false - evalStr = evalStr.replace(/null.match\(.+?\) != null/g, "false"); - evalStr = evalStr.replace(/null.match\(.+?\) == null/g, "false"); + evalStr = evalStr.replace(/null.match\(.+?\)\s*!=\s*null/g, "false"); + evalStr = evalStr.replace(/null.match\(.+?\)\s*==\s*null/g, "false"); + + evalStr = evalStr.trim(); let res; try { diff --git a/tests/rules-regex.test.ts b/tests/rules-regex.test.ts index d24f29e26..8ad4c65c3 100644 --- a/tests/rules-regex.test.ts +++ b/tests/rules-regex.test.ts @@ -72,6 +72,11 @@ const tests = [ jsExpression: '"23".match(/1234/) != null', evalResult: false, }, + { + rule: '$CI_COMMIT_BRANCH && $GITLAB_FEATURES =~ /\bdependency_scanning\b/ && $CI_GITLAB_FIPS_MODE == "true"', + jsExpression: 'null && false && null == "true"', + evalResult: false, + }, ]; /* eslint-enable @typescript-eslint/quotes */