Skip to content

Commit

Permalink
fix: prevent dev server crash 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 b45f4ad commit b1c27a2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 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,19 @@ 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.statusCode = 404
res.end(`Bad request: ${e.message}`)
return
}


const withoutQuery = cleanUrl(url)

Expand Down

0 comments on commit b1c27a2

Please sign in to comment.