Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stepfunctions): JsonPath does not support path with array #10553

Merged
merged 2 commits into from
Sep 29, 2020
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
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