gatsby
gatsby copied to clipboard
Build breaks if `pagePath` contains `%` character
Preliminary Checks
- [X] This issue is not a duplicate. Before opening a new issue, please search existing issues: https://github.com/gatsbyjs/gatsby/issues
- [X] This issue is not a question, feature request, RFC, or anything other than a bug report directly related to Gatsby. Please post those things in GitHub Discussions: https://github.com/gatsbyjs/gatsby/discussions
Description
As it is stated in Gatsby docs, page paths must not be pre-encoded.
If a page path contains % character, the build breaks.
https://github.com/Leksat/my-gatsby-site/blob/5e54e7cf6aa2e4fac914d5c6a6b4c00d25af5e33/gatsby-node.ts#L7
This is because decodeURIComponent is applied to paths in @gatsbyjs/reach-router:
https://github.com/gatsbyjs/reach-router/blob/ccbdf3e10d6501093abd4f15e80f6261e5c7b036/src/lib/utils.js#L68
Reproduction Link
https://github.com/Leksat/my-gatsby-site/blob/5e54e7cf6aa2e4fac914d5c6a6b4c00d25af5e33/gatsby-node.ts#L7
Steps to Reproduce
- Create a page with
/page/%path - Run
gatsby build
Expected Result
The build passes
Actual Result
The build fails with URIError: URI malformed
Environment
System:
OS: macOS 12.5
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.19.0 - ~/.nvm/versions/node/v14.19.0/bin/node
Yarn: 1.22.17 - ~/.nvm/versions/node/v14.19.0/bin/yarn
npm: 6.14.16 - ~/.nvm/versions/node/v14.19.0/bin/npm
npmPackages:
gatsby: ^4.20.0 => 4.20.0
Config Flags
No response
At the moment I have no idea how to fix this 😬
Thanks for filing this (and https://github.com/gatsbyjs/gatsby/issues/36348). We'll look into the best steps forward.
@Leksat I recently added those lines to the docs and wondered myself if Gatsby should support % and other special characters in the path. What is your take here? See: https://github.com/gatsbyjs/gatsby/issues/16765#issuecomment-1203476158 and https://github.com/gatsbyjs/gatsby/pull/36325
I think there was some talk of removing the decodeURIComponent line from the Gatsby internals but I'm not sure what the ramifications of that would be.
Gatsby already supports almost every possible character in the path. So I'd try to fix this issue.
I already tried to add some tests to Gatsby source, but... Gatsby is a huge project, so I failed 😅
In my company we use unicode/special-char paths (they come from a CMS) and we publish our Gatsby sites on Netlify without any issue. However, currently we remove some characters/patterns from the paths for safety reasons based on my recommendations in https://github.com/gatsbyjs/gatsby/discussions/36345#discussioncomment-3364844
Whether we fix this particular issue or not, there still can be buggy paths, like /my/../../page or /my///page. So maybe createPage should throw warnings if it sees unsafe paths?
Hiya!
This issue has gone quiet. Spooky quiet. 👻
We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks for being a part of the Gatsby community! 💪💜
Hey again!
It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks again for being part of the Gatsby community! 💪💜