Skip to content

Virtual paths unexpectedly being rewritten #20803

@marvinhagemeister

Description

@marvinhagemeister

Describe the bug

When a resolveId hook returns a namespaced path with a null byte in front, it will be rewritten regardless of that.

\0http://example.com/virtual.js -> \0https:/example.com/virtual.js

Reproduction

https://stackblitz.com/edit/vitejs-vite-gq5fry2q?file=vite.config.ts,src%2Fmain.js,index.html&terminal=dev

Steps to reproduce

Visit the minimal reproduction case, error occurs when launching vite and visiting the dev server.

// vite.config.ts
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    {
      name: 'foo',
      resolveId(id) {
        if (id === 'virtual') {
          return `\0https://example.com/virtual.js`;
        }
      },
      load(id) {
        if (id === '\0https://example.com/virtual.js') {
          return `export default "ok";`;
        }
      },
    },
  ],
});

System Info

-

Used Package Manager

npm

Logs

Click to expand!
15:52:59 [vite] (client) Pre-transform error: Failed to load url https:/example.com/virtual.js (resolved id: https:/example.com/virtual.js) in /home/projects/vitejs-vite-gq5fry2q/src/main.js. Does the file exist?

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions