Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@
{
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
{
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
{
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
}
Expand All @@ -226,7 +229,8 @@
"939a4ab8b51f1a1cccb59d97f04c318ad41c1d404e666c158ca2810894bc5f5f.zip",
"4ba8cfb53da242e91a423f3333c95db70ac0b5c2481a2d7e5c51142e5738403f.zip",
"4458891c23c9754723db261b607985ee4fce5a087343fca93e9608fb49e083ba.zip",
"c3f91ed893cc759513d80ebd56bcaae5061b08bff3dd8ad10daeb62558bac52e.zip"
"c3f91ed893cc759513d80ebd56bcaae5061b08bff3dd8ad10daeb62558bac52e.zip",
"10cb9bf43614add407e699e4af8e1ba4a9789363f48fa816662b15885c354e1a.zip"
],
"SourceMarkers": [
{},
Expand Down Expand Up @@ -329,7 +333,8 @@
]
]
}
}
},
{}
],
"SourceMarkersConfig": [
{},
Expand All @@ -340,6 +345,7 @@
{
"jsonEscape": true
},
{},
{}
],
"DestinationBucketName": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const file7 = Source.yamlData('my-yaml/secret-config.yaml', {
secret_value: tokenizedValue,
});

// case for empty string
const file8 = Source.data('file8.txt', '');

const deployment = new BucketDeployment(stack, 'DeployMeHere', {
destinationBucket: bucket,
sources: [file1, file2],
Expand All @@ -61,6 +64,7 @@ deployment.addSource(file4);
deployment.addSource(file5);
deployment.addSource(file6);
deployment.addSource(file7);
deployment.addSource(file8);

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

Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk-lib/aws-s3-deployment/lib/render-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class TokenToMarkerMapper implements ITokenMapper {
export function renderData(data: string): Content {
const tokenMapper = new TokenToMarkerMapper();

// Handle empty string case explicitly to avoid StringConcat.join(undefined, undefined)
if (data === '') {
return {
text: '',
markers: {},
};
}

return {
// Break down the string into its token fragments and replace each token with a marker.
// Then rejoin the fragments with basic string concatenation.
Expand Down
27 changes: 27 additions & 0 deletions packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,30 @@ test('lazy within a string is not resolved', () => {
},
});
});

test('renderData can render empty string data', () => {
const stack = new Stack();
expect(renderData('')).toStrictEqual({
markers: {},
text: '',
});
});

test('Source.data with empty string does not throw error', () => {
const stack = new Stack();
const handler = new lambda.Function(stack, 'Handler', {
runtime: lambda.Runtime.NODEJS_LATEST,
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
});

// This is the exact reproduction case from issue #35809
// Before the fix, this would throw: "The "data" argument must be of type string... Received undefined"
expect(() => {
const source = Source.data('path/to/empty', '');
const actual = source.bind(stack, { handlerRole: handler.role! });
expect(actual.markers).toStrictEqual({});
expect(actual.bucket).toBeDefined();
expect(actual.zipObjectKey).toBeDefined();
}).not.toThrow();
});
Loading