Skip to content

@std/path in the browser has different behavior for Windows users #6834

@alexgleason

Description

@alexgleason

Describe the bug

I am using @std/path in the browser to resolve virtual paths in a virtual terminal on a virtual filesystem, eg:

Image

But when the user uses my website from a Windows computer, everything is broken:

Image

After some digging, I found this:

export function join(path: string | URL, ...paths: string[]): string {
  return isWindows ? windowsJoin(path, ...paths) : posixJoin(path, ...paths);
}

isWindows is defined like this:

export function checkWindows(): boolean {
  // deno-lint-ignore no-explicit-any
  const global = globalThis as any;
  const os = global.Deno?.build?.os;

  // Check Deno, then the remaining runtimes (e.g. Node, Bun and the browser)
  return typeof os === "string"
    ? os === "windows"
    : global.navigator?.platform?.startsWith("Win") ??
      global.process?.platform?.startsWith("win") ?? false;
}

It checks navigator.platform, which means Windows users will get a different paths experience in a browser environment.

But that doesn't make sense in the browser... we are not dealing with a real filesystem. I think it's an unexpected behavior for the functionality to be different between platforms when used from a browser.

EDIT: Also, path-browserify does not have this problem, so switching to that solves my issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions