-
Notifications
You must be signed in to change notification settings - Fork 4.4k
(aws-stepfunctions): Condition.jsonata does not support multiline string #35912
Copy link
Copy link
Closed
Closed
Copy link
Labels
@aws-cdk/aws-stepfunctionsRelated to AWS StepFunctionsRelated to AWS StepFunctionsbugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp1
Description
Describe the bug
Condition.jsonata constructor validation fails for a multi-line JSONata strings. This is possible in other places.
const fails = `{%
true
%}`
const works = `{% true %}`
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
It should allow multiline JSONata strings, correctly detecting the opening and closing tags.
Current Behavior
Using a multiline template literal in Typescript as the condition:
const condition = `{%
true
%}`
Condition.jsonata(condition)
Throws the following on cdk synth:
JSONata expression must be start with '{%' and end with '%}', got '{%
true
%}'
Reproduction Steps
The resultJsonata is fine as multiline, but the conditionJsonata won't synth unless it's put on one line, ie. const conditionJsonata = `{% true %}`;
import { Stack } from "aws-cdk-lib";
import {
Choice,
Condition,
DefinitionBody,
Pass,
StateMachine,
} from "aws-cdk-lib/aws-stepfunctions";
import { Construct } from "constructs";
export class ConditionStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
const conditionJsonata = `{%
true
%}`;
const resultJsonata = `{%
"passed"
%}`;
const choice = Choice.jsonata(this, `${id}-Choice`);
const condition = Condition.jsonata(conditionJsonata);
const pass = Pass.jsonata(this, `${id}-Pass`, {
outputs: {
result: resultJsonata,
},
});
const definition = choice.when(condition, pass);
new StateMachine(this, `${id}-StateMachine`, {
definitionBody: DefinitionBody.fromChainable(definition),
});
}
}
Possible Solution
The validation could be updated to add the s "dotAll" flag to the regex: if (!/^{%(.*)%}$/s.test(condition)) {
or a simpler non-regex if (!(condition.startsWith("{%") && condition.endsWith("%}"))) {.
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.190.0
AWS CDK CLI version
2.1019.2 (build c29855e)
Node.js Version
20.17.0
OS
Mac
Language
TypeScript
Language Version
No response
Other information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-stepfunctionsRelated to AWS StepFunctionsRelated to AWS StepFunctionsbugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp1