Skip to content

Commit 5ba5255

Browse files
committed
fix: Incorrect extension extraction from file paths for pages prebuilt assets publish
Fixes #1029 Our extension extraction logic was taking into account folder names, which can include periods. The logic would incorrectly identify a file path of `.well-known/foo` as having the extension of `well-known/foo` when in reality it should be an empty string.
1 parent cc6e18b commit 5ba5255

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

packages/wrangler/src/__tests__/pages.test.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFileSync } from "node:fs";
1+
import { writeFile, mkdir } from "node:fs/promises";
22
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
33
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
44
import { mockConsoleMethods } from "./helpers/mock-console";
@@ -276,7 +276,7 @@ describe("pages", () => {
276276
});
277277

278278
it("should upload a directory of files", async () => {
279-
writeFileSync("logo.png", "foobar");
279+
await writeFile("logo.png", "foobar");
280280

281281
setMockResponse(
282282
"/accounts/:accountId/pages/projects/foo/file",
@@ -323,5 +323,28 @@ describe("pages", () => {
323323
// ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
324324
// `);
325325
});
326+
327+
it("should not error when directory names contain periods", async () => {
328+
await mkdir(".well-known");
329+
await writeFile(".well-known/foobar.png", "foobar");
330+
331+
setMockResponse(
332+
"/accounts/:accountId/pages/projects/foo/file",
333+
async () => ({
334+
id: "2082190357cfd3617ccfe04f340c6247",
335+
})
336+
);
337+
338+
setMockResponse(
339+
"/accounts/:accountId/pages/projects/foo/deployments",
340+
async () => ({
341+
url: "https://abcxyz.foo.pages.dev/",
342+
})
343+
);
344+
345+
await runWrangler("pages publish . --project-name=foo");
346+
347+
expect(std.err).toMatchInlineSnapshot(`""`);
348+
});
326349
});
327350
});

packages/wrangler/src/pages.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { execSync, spawn } from "node:child_process";
44
import { existsSync, lstatSync, readFileSync, writeFileSync } from "node:fs";
55
import { readdir, readFile, stat } from "node:fs/promises";
66
import { tmpdir } from "node:os";
7-
import { dirname, join, sep } from "node:path";
7+
import { dirname, join, sep, extname, basename } from "node:path";
88
import { cwd } from "node:process";
99
import { URL } from "node:url";
1010
import { hash } from "blake3-wasm";
@@ -1079,8 +1079,7 @@ const createDeployment: CommandModule<
10791079
const fileContent = await readFile(filepath);
10801080

10811081
const base64Content = fileContent.toString("base64");
1082-
const extension =
1083-
name.split(".").length > 1 ? name.split(".").at(-1) || "" : "";
1082+
const extension = extname(basename(name)).substring(1);
10841083

10851084
const content = base64Content + extension;
10861085

0 commit comments

Comments
 (0)