Skip to content

Windows UNC file URLs are not resolved or generated correctly #744

Closed

Description

@cjnoname

Summary

On Windows, file: URLs are handled by string surgery against a fixed file:/// prefix, so UNC paths — network shares, mapped drives — do not round trip.

https://github.com/oxc-project/oxc-node/blob/main/src/lib.rs#L119-L123

#[cfg(target_os = "windows")]
const PATH_PREFIX: &str = "file:///";

A valid UNC file URL is file://server/share/dir/module.ts — two slashes, with the host in the authority component. It does not start with file:///, so:

Parsing. create_resolve strips PATH_PREFIX from parentURL to find the directory to resolve from. For a UNC parent the prefix does not match and resolution fails outright:

Error: Parent URL is not a file URL

Generating. oxc_resolved_path_to_url replaces backslashes with forward slashes and concatenates onto file:///, so \\server\share\x.ts becomes

file://///server/share/x.ts     # produced
file://server/share/x.ts        # what pathToFileURL() gives

The host is lost and the slash count is wrong, so Node.js reads it back as a different path.

Impact

Projects loaded from a Windows network share, or from a UNC path that was not mapped to a drive letter, and any module graph entered through a UNC URL. Ordinary drive-letter paths (C:\...) are unaffected — file:///C:/... matches the prefix and round trips correctly, which is why the existing Windows CI jobs pass.

Suggested fix

Use the same rules as pathToFileURL/fileURLToPath instead of a prefix constant:

  • a path starting with \\ becomes file://<host>/<share>/..., with the host percent-encoded as an authority
  • everything else keeps file:///<drive>:/...
  • when parsing, a non-empty authority maps back to \\<host>\...

Worth covering with a fixture built on a UNC path in the Windows CI jobs, since a
drive-letter fixture cannot catch this.

Notes

Found while working on #633 but unrelated to it; the behaviour is the same on main. I do not have a Windows machine to verify a fix on, so I have not attempted one rather than guess at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions