From 0111931d14cf00827f6e799d6a37a5e32722f275 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 1 Nov 2022 13:48:58 +0100 Subject: [PATCH] Escape windows paths before writing wrapper templates --- packages/nextjs/src/config/loaders/prefixLoader.ts | 2 +- packages/nextjs/src/config/loaders/proxyLoader.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nextjs/src/config/loaders/prefixLoader.ts b/packages/nextjs/src/config/loaders/prefixLoader.ts index 6422941c99e5..040163409f04 100644 --- a/packages/nextjs/src/config/loaders/prefixLoader.ts +++ b/packages/nextjs/src/config/loaders/prefixLoader.ts @@ -20,7 +20,7 @@ export default function prefixLoader(this: LoaderThis, userCode: // Fill in the placeholder let templateCode = fs.readFileSync(templatePath).toString(); - templateCode = templateCode.replace('__DIST_DIR__', distDir); + templateCode = templateCode.replace('__DIST_DIR__', distDir.replace(/\\/g, '\\\\')); return `${templateCode}\n${userCode}`; } diff --git a/packages/nextjs/src/config/loaders/proxyLoader.ts b/packages/nextjs/src/config/loaders/proxyLoader.ts index 323294a38504..50e90317f223 100644 --- a/packages/nextjs/src/config/loaders/proxyLoader.ts +++ b/packages/nextjs/src/config/loaders/proxyLoader.ts @@ -47,12 +47,12 @@ export default async function proxyLoader(this: LoaderThis, userC : 'pageProxyLoaderTemplate.js'; const templatePath = path.resolve(__dirname, `../templates/${templateFile}`); let templateCode = fs.readFileSync(templatePath).toString(); - // Make sure the template is included when runing `webpack watch` + // Make sure the template is included when running `webpack watch` this.addDependency(templatePath); // Inject the route and the path to the file we're wrapping into the template - templateCode = templateCode.replace(/__ROUTE__/g, parameterizedRoute); - templateCode = templateCode.replace(/__RESOURCE_PATH__/g, this.resourcePath); + templateCode = templateCode.replace(/__ROUTE__/g, parameterizedRoute.replace(/\\/g, '\\\\')); + templateCode = templateCode.replace(/__RESOURCE_PATH__/g, this.resourcePath.replace(/\\/g, '\\\\')); // Run the proxy module code through Rollup, in order to split the `export * from ''` out into // individual exports (which nextjs seems to require).