Unverified Commit 6bd789da authored by Shu Ding's avatar Shu Ding Committed by GitHub

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)
parent 56b097a8
...@@ -94,7 +94,7 @@ async function createTreeCodeFromPath({ ...@@ -94,7 +94,7 @@ async function createTreeCodeFromPath({
} }
return `${ return `${
file === FILE_TYPES.layout file === FILE_TYPES.layout
? `layoutOrPagePath: '${filePath}',` ? `layoutOrPagePath: ${JSON.stringify(filePath)},`
: '' : ''
}'${file}': () => require(${JSON.stringify(filePath)}),` }'${file}': () => require(${JSON.stringify(filePath)}),`
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment