Skip to content

Commit

Permalink
fix: cloud.Website in AWS does not escape Windows path for assets (#4478
Browse files Browse the repository at this point in the history
)

Fixes #4319

e2e tests are not possible since we don't deploy to AWS via windows. This would also be solved via #4288

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
MarkMcCulloh authored Oct 10, 2023
1 parent 4ec835e commit 8c8124f
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions libs/wingsdk/src/target-tf-aws/website.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readdirSync } from "fs";
import { extname, join, posix, resolve, sep } from "path";
import { extname, join, resolve } from "path";

import { Fn } from "cdktf";
import { Construct } from "constructs";
Expand All @@ -15,6 +15,7 @@ import { S3BucketPolicy } from "../.gen/providers/aws/s3-bucket-policy";
import { S3BucketWebsiteConfiguration } from "../.gen/providers/aws/s3-bucket-website-configuration";
import { S3Object } from "../.gen/providers/aws/s3-object";
import * as cloud from "../cloud";
import { normalPath } from "../shared/misc";
import { NameOptions, ResourceNames } from "../shared/resource-names";
import * as aws from "../shared-aws";

Expand Down Expand Up @@ -168,21 +169,22 @@ export class Website extends cloud.Website {
content: data,
bucket: this.bucket.bucket,
contentType: options?.contentType ?? "text/plain",
key: this.formatPath(path),
key: normalPath(path),
});

return `${this.url}/${path}`;
}

private uploadFile(filePath: string) {
const fileKey = filePath.replace(this.path, "");
const fileKey = normalPath(filePath.replace(this.path, ""));
const normalizedFullPath = normalPath(resolve(filePath));

new S3Object(this, `File${fileKey.replace(/[\/\\]/g, "--")}`, {
new S3Object(this, `File${fileKey.replace(/\//g, "--")}`, {
dependsOn: [this.bucket],
key: this.formatPath(filePath.replace(this.path, "")),
key: fileKey,
bucket: this.bucket.bucket,
source: resolve(filePath),
sourceHash: Fn.filemd5(resolve(filePath)),
source: normalizedFullPath,
sourceHash: Fn.filemd5(normalizedFullPath),
contentType: mime.contentType(extname(filePath)) || undefined,
});
}
Expand All @@ -199,10 +201,6 @@ export class Website extends cloud.Website {
}
}

private formatPath(path: string): string {
return path.split(sep).join(posix.sep);
}

/** @internal */
public _toInflight(): string {
return core.InflightClient.for(
Expand Down

0 comments on commit 8c8124f

Please sign in to comment.