fix: handle encoded base paths by bluwy · Pull Request #17577 · vitejs/vite (original) (raw)

Description

supersedes and closes #16412

Due to the changes from #15311 (and tweaks thereafter) (Vite 5.2), I believe it broke most cases of base that contains encoded base paths, e.g. /foo%20bar/, which Vite encodes internally even if you pass /foo bar/.

I'm somewhat relieved that we didn't get a lot of reports of this, because base paths that look like this are hard 🥲


Because resolvedConfig.base is a URL-encoded string, when we merge it with some un-encoded strings, and encode the merged string, the base portion will get double encoded. The solution in this PR is to decode the base first.

In the future, maybe we can revisit if we want to have resolvedConfig.base be decoded only, or introduce a new resolvedConfig.decodedBase? Or we can say we don't support strange base paths.

NOTE: I also updated the code in plugin-legacy together as I noticed it while searching the codebase.