-
Notifications
You must be signed in to change notification settings - Fork 4k
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: JsonPath.format incorrectly escapes newlines #27304
Comments
If I use the return value of JsonPath.format as a stack output, then that string is not incorrectly escaped in the synthesized template: const messageFormat = sfn.JsonPath.format('Hello\n{}', sfn.JsonPath.stringAt('$.name'));
new cdk.CfnOutput(this, 'MessageFormat', {
value: messageFormat,
}); Result: "Outputs": {
"MessageFormat": {
"Value": "States.Format('Hello\\n{}', $.name)"
}
}, So the double-escaping could be happening when the DefinitionString is created in the StateMachine construct |
It looks like this is where the double-escaping could be happening - when toJsonString is called on the state machine graph JSON, after JsonPath.format has already escaped the newlines: Example of doing toJsonString on my Pass state in a stack output vs what comes out of JsonPath.format: const messageFormat = sfn.JsonPath.format('Hello\n{}', sfn.JsonPath.stringAt('$.name'));
const messageState = new sfn.Pass(this, 'MessageState', {
parameters: {
"message": messageFormat,
},
});
new cdk.CfnOutput(this, 'MessageFormat', {
value: messageFormat,
});
new cdk.CfnOutput(this, 'MessageStateDef', {
value: cdk.Stack.of(this).toJsonString(messageState.toStateJson()),
}); Output: "Outputs": {
"MessageFormat": {
"Value": "States.Format('Hello\\n{}', $.name)"
},
"MessageStateDef": {
"Value": "{\"Type\":\"Pass\",\"Parameters\":{\"message.$\":\"States.Format('Hello\\\\n{}', $.name)\"},\"End\":true}"
}
},
|
Thanks for the investigation and PR 🙂 Much appreciated! |
…rinsics caused schema validation failures (#27323) Closes #27304. I ran the updated integ test without the code change and it correctly failed to deploy with a SCHEMA_VALIDATION_FAILED error, then it successfully deployed after the code change. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Describe the bug
When I call JsonPath.format with a string that contains newlines, the resulting string in the CloudFormation template is escaped too many times and fails to deploy.
The example in the repro steps produces this template snippet. Note the two extra backslashes for the newline in
States.Format('Hello\\\\n{}'
.Expected Behavior
Template can be successfully deployed.
If I manually edit the synthesized template to remove the two extra backslashes for the newline (
States.Format('Hello\\n{}'
), then the template can be successfully deployed and the state machine has the correct newline in its output:Current Behavior
The template fails to deploy with:
Reproduction Steps
Possible Solution
The escaping logic for newlines here for JsonPath.format seems to be right, so I'm wondering if there's another round of escaping that's happening when the template is synthesized:
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-stepfunctions/lib/private/json-path.ts#L340-L356
Additional Information/Context
No response
CDK CLI Version
2.98.0
Framework Version
2.98.0
Node.js Version
v18.17.1
OS
Linux
Language
Typescript
Language Version
Typescript (5.2.2)
Other information
No response
The text was updated successfully, but these errors were encountered: