Skip to content

Commit 95c8d73

Browse files
fix(s3-deployment): handle empty string in Source.data() (#35824)
### Issue # (if applicable) Closes #35809. Original PR: #35818 This PR is been created to fasten release of the fix for the p0 ### Reason for this change `Source.data()` fails with a TypeError when called with an empty string as the data parameter in CDK v2.207.0+. This is a regression from v2.206.0 where empty string deployment worked correctly. The issue manifests as: ``` TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined at Object.writeFileSync (node:fs:2434:5) ``` ### Description of changes This change handles the the case from renderData function. ### Describe any new or updated permissions being added ### Description of how you validated changes Unit tests have been added to cover this case and integ test has also been updated. ### 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 c5e7f21 commit 95c8d73

File tree

11 files changed

+127
-28
lines changed

11 files changed

+127
-28
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/TestBucketDeploymentContent.assets.json

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/TestBucketDeploymentContent.template.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@
215215
{
216216
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
217217
},
218+
{
219+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
220+
},
218221
{
219222
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
220223
}
@@ -226,7 +229,8 @@
226229
"939a4ab8b51f1a1cccb59d97f04c318ad41c1d404e666c158ca2810894bc5f5f.zip",
227230
"4ba8cfb53da242e91a423f3333c95db70ac0b5c2481a2d7e5c51142e5738403f.zip",
228231
"4458891c23c9754723db261b607985ee4fce5a087343fca93e9608fb49e083ba.zip",
229-
"c3f91ed893cc759513d80ebd56bcaae5061b08bff3dd8ad10daeb62558bac52e.zip"
232+
"c3f91ed893cc759513d80ebd56bcaae5061b08bff3dd8ad10daeb62558bac52e.zip",
233+
"10cb9bf43614add407e699e4af8e1ba4a9789363f48fa816662b15885c354e1a.zip"
230234
],
231235
"SourceMarkers": [
232236
{},
@@ -329,7 +333,8 @@
329333
]
330334
]
331335
}
332-
}
336+
},
337+
{}
333338
],
334339
"SourceMarkersConfig": [
335340
{},
@@ -340,6 +345,7 @@
340345
{
341346
"jsonEscape": true
342347
},
348+
{},
343349
{}
344350
],
345351
"DestinationBucketName": {

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/asset.10cb9bf43614add407e699e4af8e1ba4a9789363f48fa816662b15885c354e1a/file8.txt

Whitespace-only changes.

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/asset.4e818c462cf84c112f84262d376efd099d66da03f7a2aabae64c50c0511de276.bundle/index.js renamed to packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/asset.c11608a15785084ea1afe65826e575ee316add10c8b1bb373e93297e26aec564.bundle/index.js

Lines changed: 23 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/integtestbucketdeploymentdataDefaultTestDeployAssert6FF3075D.assets.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/integtestbucketdeploymentdataDefaultTestDeployAssert6FF3075D.template.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/manifest.json

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.js.snapshot/tree.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const file7 = Source.yamlData('my-yaml/secret-config.yaml', {
5050
secret_value: tokenizedValue,
5151
});
5252

53+
// case for empty string
54+
const file8 = Source.data('file8.txt', '');
55+
5356
const deployment = new BucketDeployment(stack, 'DeployMeHere', {
5457
destinationBucket: bucket,
5558
sources: [file1, file2],
@@ -61,6 +64,7 @@ deployment.addSource(file4);
6164
deployment.addSource(file5);
6265
deployment.addSource(file6);
6366
deployment.addSource(file7);
67+
deployment.addSource(file8);
6468

6569
new CfnOutput(stack, 'BucketName', { value: bucket.bucketName });
6670

packages/aws-cdk-lib/aws-s3-deployment/lib/render-data.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ class TokenToMarkerMapper implements ITokenMapper {
3434
export function renderData(data: string): Content {
3535
const tokenMapper = new TokenToMarkerMapper();
3636

37+
// Handle empty string case explicitly to avoid StringConcat.join(undefined, undefined)
38+
if (data === '') {
39+
return {
40+
text: '',
41+
markers: {},
42+
};
43+
}
44+
3745
return {
3846
// Break down the string into its token fragments and replace each token with a marker.
3947
// Then rejoin the fragments with basic string concatenation.

0 commit comments

Comments
 (0)