Skip to content

Commit

Permalink
fix: prevent dev server crashing on malformed URI (fix vitejs#6300)
Browse files Browse the repository at this point in the history
  • Loading branch information
toSayNothing committed Dec 29, 2021
1 parent d856c4b commit 776ebef
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ export function transformMiddleware(
}
}

let url = decodeURI(removeTimestampQuery(req.url!)).replace(
NULL_BYTE_PLACEHOLDER,
'\0'
)
let url:string
try {
url = decodeURI(removeTimestampQuery(req.url!)).replace(
NULL_BYTE_PLACEHOLDER,
'\0'
)
} catch (e) {
res.end(`Bad request: ${e.message}`)
return
}

const withoutQuery = cleanUrl(url)

Expand Down

0 comments on commit 776ebef

Please sign in to comment.