Skip to content

Commit

Permalink
fix(module-runner): decode uri for file url passed to import (#18837)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Dec 2, 2024
1 parent 3104331 commit 88e49aa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite/src/module-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function normalizeAbsoluteUrl(url: string, root: string): string {
// file:///C:/root/id.js -> C:/root/id.js
if (url.startsWith('file://')) {
// 8 is the length of "file:///"
url = url.slice(isWindows ? 8 : 7)
url = decodeURI(url.slice(isWindows ? 8 : 7))
}

// strip root from the URL because fetchModule prefers a public served url path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = 'works'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = 'works'
14 changes: 14 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,17 @@ test('json', async () => {
)
expect(json?.code.length).toMatchInlineSnapshot(`61`)
})

test('file url', async () => {
const server = await createDevServer()

const mod = await server.ssrLoadModule(
new URL('./fixtures/file-url/test.js', import.meta.url).href,
)
expect(mod.msg).toBe('works')

const modWithSpace = await server.ssrLoadModule(
new URL('./fixtures/file-url/test space.js', import.meta.url).href,
)
expect(modWithSpace.msg).toBe('works')
})

0 comments on commit 88e49aa

Please sign in to comment.