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

aws-stepfunctions: Escaping curly braces not supported in intrinsic functions #29261

Closed
clareliguori opened this issue Feb 26, 2024 · 2 comments · Fixed by #29267
Closed

aws-stepfunctions: Escaping curly braces not supported in intrinsic functions #29261

clareliguori opened this issue Feb 26, 2024 · 2 comments · Fixed by #29267
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@clareliguori
Copy link
Member

Describe the bug

I am trying to escape curly braces in a state machine definition, for example:

const pass = new Pass(stack, 'pass', {
  parameters: {
    format: JsonPath.format('Hello {}, please format your response in JSON. For example: \\{ "name": "Bob" \\}', JsonPath.stringAt('$.Name')),
  },
});

Note that the first set of curly braces in the format string are for injecting the 'Name' field, and the second set are escaped using backslashes.

Expected Behavior

The resulting definition has the curly braces properly escaped.

Current Behavior

The escaping backslash before each curly brace is doubly-escaped, leading to an error when I try to execute the state machine:

Invalid template in States.Format: matching '}' not found for '{'.

The state definition when deployed to Step Functions shows double-escaping:

Hello {}, please format your response in JSON. For example: \\\\{ "name": "Bob" \\\\}

Reproduction Steps

See example above

Possible Solution

The logic here incorrectly assumes all backslashes should be escaped:
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-stepfunctions/lib/private/json-path.ts#L346-L347

Additional Information/Context

No response

CDK CLI Version

2.122.0

Framework Version

No response

Node.js Version

v18.19.1

OS

Linux

Language

TypeScript

Language Version

No response

Other information

No response

@clareliguori clareliguori added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2024
@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Feb 26, 2024
@tim-finnigan tim-finnigan self-assigned this Feb 26, 2024
@tim-finnigan
Copy link

Thanks for reporting this issue and submitting the PR!

@tim-finnigan tim-finnigan added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2024
@tim-finnigan tim-finnigan removed their assignment Feb 26, 2024
@clareliguori clareliguori changed the title aws-stepfunctions: Escaping curly braces not supported in States Language aws-stepfunctions: Escaping curly braces not supported in intrinsic functions Feb 26, 2024
@mergify mergify bot closed this as completed in #29267 Feb 26, 2024
mergify bot pushed a commit that referenced this issue Feb 26, 2024
… machine execution (#29267)

### Issue # (if applicable)

Closes #29261

### Reason for this change

Enable proper escaping of curly braces in Step Functions intrinsic functions. The user needs to be able to explicitly escape curly braces to distinguish them from curly braces used for intrinsic function arguments (`\{\}` vs `{}`.  Currently, the escaping logic double-escapes an already-escaped curly brace. The state machine successfully deploys, but then fails to execute.

### Description of changes

When a backslash immediately precedes a curly brace, it will not be escaped.

### Description of how you validated changes

Added a case to an existing integration test, and updated the integ test to execute the deployed state machine to check for runtime errors.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
2 participants