From 826f84e59507a843fe4223e02618015ce5da17da Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Thu, 20 Oct 2022 20:41:25 +0200 Subject: [PATCH] Fix missing JSON.stringify in loader (#41599) We can't directly put `filePath` in the generated code as it can contain in valid JavaScript string such as `"\2"` in `"C:\Users\foo\2022\bar.js"`. Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal Reported issue in Next.js: ![image](https://user-images.githubusercontent.com/3676859/196962933-0a3bf4b4-9142-426f-9ac5-bdcfb3c5ebf0.png) ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- packages/next/build/webpack/loaders/next-app-loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/build/webpack/loaders/next-app-loader.ts b/packages/next/build/webpack/loaders/next-app-loader.ts index 515417f016aa8..1cb65e7e84323 100644 --- a/packages/next/build/webpack/loaders/next-app-loader.ts +++ b/packages/next/build/webpack/loaders/next-app-loader.ts @@ -94,7 +94,7 @@ async function createTreeCodeFromPath({ } return `${ file === FILE_TYPES.layout - ? `layoutOrPagePath: '${filePath}',` + ? `layoutOrPagePath: ${JSON.stringify(filePath)},` : '' }'${file}': () => require(${JSON.stringify(filePath)}),` })