Skip to content

Commit

Permalink
fix(stepfunctions): JsonPath not supporting array paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush987goyal committed Sep 29, 2020
1 parent d68ce2f commit f52b939
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 7 additions & 2 deletions packages/@aws-cdk/aws-stepfunctions/lib/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,13 @@ export class FieldUtils {
}

function validateJsonPath(path: string) {
if (path !== '$' && !path.startsWith('$.') && path !== '$$' && !path.startsWith('$$.')) {
throw new Error(`JSON path values must be exactly '$', '$$', start with '$.' or start with '$$.' Received: ${path}`);
if (path !== '$'
&& !path.startsWith('$.')
&& path !== '$$'
&& !path.startsWith('$$.')
&& !path.startsWith('$[')
) {
throw new Error(`JSON path values must be exactly '$', '$$', start with '$.', start with '$$.' or start with '$[' Received: ${path}`);
}
}

Expand Down
16 changes: 10 additions & 6 deletions packages/@aws-cdk/aws-stepfunctions/test/fields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import '@aws-cdk/assert/jest';
import { FieldUtils, JsonPath } from '../lib';

describe('Fields', () => {
const jsonPathValidationErrorMsg = /exactly '\$', '\$\$', start with '\$.', start with '\$\$.' or start with '\$\['/;

test('deep replace correctly handles fields in arrays', () => {
expect(
FieldUtils.renderObject({
Expand Down Expand Up @@ -70,16 +72,18 @@ describe('Fields', () => {
test('datafield path must be correct', () => {
expect(JsonPath.stringAt('$')).toBeDefined();

expect(() => JsonPath.stringAt('$hello')).toThrowError(/exactly '\$', '\$\$', start with '\$.' or start with '\$\$.'/);

expect(() => JsonPath.stringAt('hello')).toThrowError(/exactly '\$', '\$\$', start with '\$.' or start with '\$\$.'/);
expect(() => JsonPath.stringAt('$hello')).toThrowError(jsonPathValidationErrorMsg);
expect(() => JsonPath.stringAt('hello')).toThrowError(jsonPathValidationErrorMsg);
}),
test('context path must be correct', () => {
expect(JsonPath.stringAt('$$')).toBeDefined();

expect(() => JsonPath.stringAt('$$hello')).toThrowError(/exactly '\$', '\$\$', start with '\$.' or start with '\$\$.'/);

expect(() => JsonPath.stringAt('hello')).toThrowError(/exactly '\$', '\$\$', start with '\$.' or start with '\$\$.'/);
expect(() => JsonPath.stringAt('$$hello')).toThrowError(jsonPathValidationErrorMsg);
expect(() => JsonPath.stringAt('hello')).toThrowError(jsonPathValidationErrorMsg);
}),
test('datafield path with array must be correct', () => {
expect(JsonPath.stringAt('$[0]')).toBeDefined();
expect(JsonPath.stringAt("$['abc']")).toBeDefined();
}),
test('test contains task token', () => {
expect(true).toEqual(
Expand Down

0 comments on commit f52b939

Please sign in to comment.