diff --git a/.changeset/thick-oranges-smoke.md b/.changeset/thick-oranges-smoke.md new file mode 100644 index 000000000..95dd8b20f --- /dev/null +++ b/.changeset/thick-oranges-smoke.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +fix: shell quoting on windows machines to avoid upload errors for routes with `[...path]` segments diff --git a/packages/cloudflare/src/cli/commands/helpers.ts b/packages/cloudflare/src/cli/commands/helpers.ts index 4f1149ec1..85b6a0ecd 100644 --- a/packages/cloudflare/src/cli/commands/helpers.ts +++ b/packages/cloudflare/src/cli/commands/helpers.ts @@ -83,6 +83,18 @@ export async function getEnvFromPlatformProxy(options: GetPlatformProxyOptions, * @returns escaped arg */ export function quoteShellMeta(arg: string) { + if (process.platform === "win32") { + if (arg.length === 0) { + return '""'; + } + const needsEscaping = /[&|<>^()%!"]/; + const needsQuotes = /\s/.test(arg) || needsEscaping.test(arg); + let escaped = arg.replace(/"/g, '""'); + if (/[&|<>^()%!]/.test(arg)) { + escaped = escaped.replace(/[&|<>^()%!]/g, "^$&"); + } + return needsQuotes ? `"${escaped}"` : escaped; + } if (/["\s]/.test(arg) && !/'/.test(arg)) { return `'${arg.replace(/(['\\])/g, "\\$1")}'`; }