@std/path in the browser has different behavior for Windows users
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I am using `@std/path` in the browser to resolve virtual paths in a virtual terminal on a virtual filesystem, eg:
But when the user uses my website from a Windows computer, everything is broken:
After some digging, I found this:
```ts
export function join(path: string | URL, ...paths: string[]): string {
return isWindows ? windowsJoin(path, ...paths) : posixJoin(path, ...paths);
}
```
`isWindows` is defined like this:
```ts
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.
Contributor guide
Assessment
This issue has not been assessed yet.