Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export class Utils {

static evaluateRuleIf (ruleIf: string | undefined, envs: {[key: string]: string}): boolean {
if (ruleIf === undefined) return true;
assert(typeof ruleIf === "string", chalk`This GitLab CI configuration is invalid: {blueBright rules:if} must be a string, but got {red ${JSON.stringify(ruleIf)}}`);
assert(!/\$\{\w+\}/.test(ruleIf), chalk`rules:rule if invalid expression syntax: {blueBright ${ruleIf}}\nuse {green $VAR} not {red \${VAR\}} in rules:if`);
let evalStr = ruleIf;

Expand Down
8 changes: 8 additions & 0 deletions tests/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,11 @@ test.concurrent("https://github.com/firecow/gitlab-ci-local/issues/1252", () =>
const rulesResult = Utils.getRulesResult({argv, cwd: "", rules, variables}, gitData);
expect(rulesResult).toEqual({when: "on_success", allowFailure: false, variables: undefined});
});

test.concurrent("https://github.com/firecow/gitlab-ci-local/issues/1841", () => {
for (const ruleIf of [null, 1, true, ["a"]]) {
const rules = [ {if: ruleIf} as any ];
expect(() => Utils.getRulesResult({argv, cwd: "", rules, variables: {}}, gitData))
.toThrow(/must be a string, but got/);
}
});