Skip to content

Commit 621e0b3

Browse files
authored
fix(nextjs): Escape Windows paths when writing wrapper templates (#6101)
1 parent aad2f85 commit 621e0b3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/nextjs/src/config/loaders/prefixLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function prefixLoader(this: LoaderThis<LoaderOptions>, userCode:
2020

2121
// Fill in the placeholder
2222
let templateCode = fs.readFileSync(templatePath).toString();
23-
templateCode = templateCode.replace('__DIST_DIR__', distDir);
23+
templateCode = templateCode.replace('__DIST_DIR__', distDir.replace(/\\/g, '\\\\'));
2424

2525
return `${templateCode}\n${userCode}`;
2626
}

packages/nextjs/src/config/loaders/proxyLoader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export default async function proxyLoader(this: LoaderThis<LoaderOptions>, userC
4747
: 'pageProxyLoaderTemplate.js';
4848
const templatePath = path.resolve(__dirname, `../templates/${templateFile}`);
4949
let templateCode = fs.readFileSync(templatePath).toString();
50-
// Make sure the template is included when runing `webpack watch`
50+
// Make sure the template is included when running `webpack watch`
5151
this.addDependency(templatePath);
5252

5353
// Inject the route and the path to the file we're wrapping into the template
54-
templateCode = templateCode.replace(/__ROUTE__/g, parameterizedRoute);
55-
templateCode = templateCode.replace(/__RESOURCE_PATH__/g, this.resourcePath);
54+
templateCode = templateCode.replace(/__ROUTE__/g, parameterizedRoute.replace(/\\/g, '\\\\'));
55+
templateCode = templateCode.replace(/__RESOURCE_PATH__/g, this.resourcePath.replace(/\\/g, '\\\\'));
5656

5757
// Run the proxy module code through Rollup, in order to split the `export * from '<wrapped file>'` out into
5858
// individual exports (which nextjs seems to require).

0 commit comments

Comments
 (0)