Skip to content

Commit

Permalink
fix(gatsby): Don't throw when a path with special character is visited (
Browse files Browse the repository at this point in the history
#36414) (#36757)

Co-authored-by: Jude Agboola <marvinjudehk@gmail.com>
  • Loading branch information
gatsbybot and marvinjude committed Oct 7, 2022
1 parent b264d17 commit 87140c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/gatsby/src/commands/develop-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ module.exports = async (program: IDevelopArgs): Promise<void> => {
const app = express()
const parentSpan = tracer.startSpan(`bootstrap`)

app.use((req, res, next) => {
try {
decodeURIComponent(req.path)
} catch (e) {
return res.status(500).send(`URI malformatted`)
}

return next()
})

const machine = developMachine.withContext({
program,
parentSpan,
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby/src/utils/find-page-by-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export function findPageByPath(
): IGatsbyPage | undefined {
const { pages } = state

path = decodeURIComponent(path)
try {
path = decodeURIComponent(path)
} catch {
// no handling, just continue using path as-is
}

// first check by exact path
let page = pages.get(path)
Expand Down

0 comments on commit 87140c9

Please sign in to comment.