Skip to content

Commit

Permalink
fix(stepfunctions): valid reference path '$' fails with an error (#6483)
Browse files Browse the repository at this point in the history
'$' is a valid reference path that indicates that the entire object
should be selected.

'$$' is a valid selection of the context object that indicates that the
entire context object should be selected.

fixes #6388

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
nija-at and mergify[bot] authored Feb 27, 2020
1 parent ee8f169 commit 221c83b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-stepfunctions/lib/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ export class FieldUtils {
}

function validateDataPath(path: string) {
if (!path.startsWith('$.')) {
throw new Error("Data JSON path values must start with '$.'");
if (path !== '$' && !path.startsWith('$.')) {
throw new Error("Data JSON path values must either be exactly equal to '$' or start with '$.'");
}
}

function validateContextPath(path: string) {
if (!path.startsWith('$$.')) {
throw new Error("Context JSON path values must start with '$$.'");
if (path !== '$$' && !path.startsWith('$$.')) {
throw new Error("Context JSON path values must either be exactly equal to '$$' or start with '$$.'");
}
}
16 changes: 14 additions & 2 deletions packages/@aws-cdk/aws-stepfunctions/test/test.fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,29 @@ export = {
},

'datafield path must be correct'(test: Test) {
test.ok(Data.stringAt('$'));

test.throws(() => {
Data.stringAt('$hello');
}, /exactly equal to '\$' or start with '\$.'/);

test.throws(() => {
Data.stringAt('hello');
}, /must start with '\$.'/);
}, /exactly equal to '\$' or start with '\$.'/);

test.done();
},

'context path must be correct'(test: Test) {
test.ok(Context.stringAt('$$'));

test.throws(() => {
Context.stringAt('$$hello');
}, /exactly equal to '\$\$' or start with '\$\$.'/);

test.throws(() => {
Context.stringAt('hello');
}, /must start with '\$\$.'/);
}, /exactly equal to '\$\$' or start with '\$\$.'/);

test.done();
},
Expand Down

0 comments on commit 221c83b

Please sign in to comment.