Skip to content

Commit 88e49aa

Browse files
authored
fix(module-runner): decode uri for file url passed to import (#18837)
1 parent 3104331 commit 88e49aa

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

packages/vite/src/module-runner/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function normalizeAbsoluteUrl(url: string, root: string): string {
77
// file:///C:/root/id.js -> C:/root/id.js
88
if (url.startsWith('file://')) {
99
// 8 is the length of "file:///"
10-
url = url.slice(isWindows ? 8 : 7)
10+
url = decodeURI(url.slice(isWindows ? 8 : 7))
1111
}
1212

1313
// strip root from the URL because fetchModule prefers a public served url path
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const msg = 'works'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const msg = 'works'

packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,17 @@ test('json', async () => {
237237
)
238238
expect(json?.code.length).toMatchInlineSnapshot(`61`)
239239
})
240+
241+
test('file url', async () => {
242+
const server = await createDevServer()
243+
244+
const mod = await server.ssrLoadModule(
245+
new URL('./fixtures/file-url/test.js', import.meta.url).href,
246+
)
247+
expect(mod.msg).toBe('works')
248+
249+
const modWithSpace = await server.ssrLoadModule(
250+
new URL('./fixtures/file-url/test space.js', import.meta.url).href,
251+
)
252+
expect(modWithSpace.msg).toBe('works')
253+
})

0 commit comments

Comments
 (0)