Skip to content

Commit 21a7a49

Browse files
authored
chore: handle quotes properly in metadata updater (#34990)
### Issue # (if applicable) Related to #34863. ### Reason for this change Because the linked PR contains quotes inside the enum values, the metadata updater produces invalid typescript code: see fe7e986 ### Description of changes This change fixes the handling of the cases: Single quotes inside an enum value: `'\''`, instead of being translated to `'''` (which is not valid typescript), will be escaped properly. Double quotes inside an enum value: `'"'` will get translated to `'\''` (which is valid typescript but not what we expect), will be escaped properly. ### Description of how you validated changes Ran the Github workflow in my account, and then built the created PR and ran unit+integ tests ### 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 c0d27ee commit 21a7a49

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/@aws-cdk/construct-metadata-updater/lib/metadata-updater.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,8 @@ export class EnumsUpdater extends MetadataUpdater {
724724
* Generate the file content for the enum metadats.
725725
*/
726726
private generateFileContent(enums: Record<string, (string | number)[]> = {}): string {
727-
const template = `/* eslint-disable quote-props */
727+
const template = `/* eslint-disable quotes */
728+
/* eslint-disable quote-props */
728729
/* eslint-disable @stylistic/comma-dangle */
729730
/* eslint-disable @cdklabs/no-literal-partition */
730731
/*
@@ -742,7 +743,7 @@ export const AWS_CDK_ENUMS: { [key: string]: any } = $ENUMS;
742743
acc[key] = enums[key];
743744
return acc;
744745
}, {});
745-
const jsonContent = JSON.stringify(sortedEnums, null, 2).replace(/"/g, "'");
746+
const jsonContent = JSON.stringify(sortedEnums, null, 2);
746747

747748
// Replace the placeholder with the JSON object
748749
return template.replace("$ENUMS", jsonContent);

0 commit comments

Comments
 (0)