Skip to content

Commit 47203f4

Browse files
jogoldmergify[bot]
authored andcommitted
fix(stepfunctions): allow condition on array (#4340)
* fix(stepfunctions): allow condition on array A Choice state after a Parallel state receives an array as input. * use regex
1 parent 6216c4d commit 47203f4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/@aws-cdk/aws-stepfunctions/lib/condition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ enum CompoundOperator {
177177
class VariableComparison extends Condition {
178178
constructor(private readonly variable: string, private readonly comparisonOperator: ComparisonOperator, private readonly value: any) {
179179
super();
180-
if (!variable.startsWith('$.')) {
181-
throw new Error(`Variable reference must start with '$.', got '${variable}'`);
180+
if (!/^\$[.[]/.test(variable)) {
181+
throw new Error(`Variable reference must start with '$.' or '$[', got '${variable}'`);
182182
}
183183
}
184184

packages/@aws-cdk/aws-stepfunctions/test/test.condition.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@ import { Test } from 'nodeunit';
22
import stepfunctions = require('../lib');
33

44
export = {
5-
'Condition variables must start with $.'(test: Test) {
5+
'Condition variables must start with $. or $['(test: Test) {
66
test.throws(() => {
77
stepfunctions.Condition.stringEquals('a', 'b');
88
});
99

1010
test.done();
1111
},
12+
'Condition variables can start with $.'(test: Test) {
13+
test.doesNotThrow(() => {
14+
stepfunctions.Condition.stringEquals('$.a', 'b');
15+
});
16+
17+
test.done();
18+
},
19+
'Condition variables can start with $['(test: Test) {
20+
test.doesNotThrow(() => {
21+
stepfunctions.Condition.stringEquals('$[0]', 'a');
22+
});
23+
24+
test.done();
25+
},
1226
'NotConditon must render properly'(test: Test) {
1327
assertRendersTo(test,
1428
stepfunctions.Condition.not(stepfunctions.Condition.stringEquals('$.a', 'b')),

0 commit comments

Comments
 (0)