Skip to content

Commit 7c4eb71

Browse files
authored
fix(stepfunctions): regex in DistributedMap label is incorrectly escaping characters (#29765)
Regex is incorrect. Switching to basic regex. Fixing regex to properly escape special characters ### Reason for this change Regex was incorrectly escaping the `]` character, and as such was falsely returning `true`. It also seemed to be interpreting the `\` characters incorrectly, so I switched to a regex literal in line to fix that. ### Description of changes Switch from `RegExp` object to inline regex. Fix regex to correctly escape `]` character. ### Description of how you validated changes Running in Node CLI, such as: ```node > /[\s\?\*\<\>\{\}\\[\]\:\;\,\|\^\~\$\#\%\&\`\"]|[\u0000-\u001f]|[\u007f-\u009f]/gi.test(' ') true ``` Running in Chrome Dev Tools console, such as: ```js new RegExp("/[\s\?\*\<\>\{\}\\[\]\:\;\,\|\^\~\$\#\%\&\`\"]|[\u0000-\u001f]|[\u007f-\u009f]/gi").test(' ') false ``` no ### 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*
1 parent fc890df commit 7c4eb71

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/aws-cdk-lib/aws-stepfunctions/lib/states/distributed-map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class DistributedMap extends MapBase implements INextable {
172172
errors.push('label must be 40 characters or less');
173173
}
174174

175-
let labelRegex = new RegExp('[\s\?\*\<\>\{\}\\[\\]\:\;\,\\\|\^\~\$\#\%\&\`\"]|[\u0000-\u001f]|[\u007f-\u009f]', 'gi');
175+
let labelRegex = /[\s\?\*\<\>\{\}\\[\]\:\;\,\|\^\~\$\#\%\&\`\"]|[\u0000-\u001f]|[\u007f-\u009f]/gi;
176176
if (labelRegex.test(this.label)) {
177177
errors.push('label cannot contain any whitespace or special characters');
178178
}

packages/aws-cdk-lib/aws-stepfunctions/test/distributed-map.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,19 @@ describe('Distributed Map State', () => {
765765

766766
expect(() => app.synth()).toThrow(/label cannot contain any whitespace or special characters/);
767767
});
768+
769+
test('does not fail in synthesis if label has `s`', () => {
770+
const app = createAppWithMap((stack) => {
771+
const map = new stepfunctions.DistributedMap(stack, 'Map State', {
772+
label: 's',
773+
itemsPath: stepfunctions.JsonPath.stringAt('$.inputForMap'),
774+
});
775+
776+
return map;
777+
});
778+
779+
app.synth();
780+
});
768781
});
769782

770783
function render(sm: stepfunctions.IChainable) {
@@ -777,4 +790,4 @@ function createAppWithMap(mapFactory: (stack: cdk.Stack) => stepfunctions.Distri
777790
const map = mapFactory(stack);
778791
new stepfunctions.StateGraph(map, 'Test Graph');
779792
return app;
780-
}
793+
}

0 commit comments

Comments
 (0)