ITADN

@std/path/posix errors on https URLs despite documentation implying the contrary

#7133Openjeremy-code 创建于 2026-05-11
bugpath
J
jeremy-codecommented
**Describe the bug** Per documentation on [@std/url](https://jsr.io/@std/url/doc): > Use functions from [@std/path/posix](https://jsr.io/@std/path/doc/posix/~) instead (examples included). @std/url will be removed in the future. However, using basename from @std/path/posix on a URL errors when the URL has a https protocol. The @std/url documentation seems to imply this should not be the case: ```ts ... const url = new URL("https:///deno.land///std//assert//.//mod.ts"); const normalizedUrl = normalize(url); assertEquals(normalizedUrl.href, "https://deno.land/std/assert/mod.ts"); assertEquals(basename(normalizedUrl), "mod.ts"); // Correctly gets basename from http URL ... ``` **Steps to Reproduce** ``` import { basename } from "@std/path/posix/basename"; const urlBasename = basename(new URL("https://jsr.io/@std/path/doc/posix/~/basename")); ``` ``` Uncaught TypeError: URL must be a file URL: received "https:" at assertArg (file:///$HOME/$WORKSPACE/node_modules/.pnpm/@jsr+std__path@1.1.4/node_modules/@jsr/std__path/_common/from_file_url.js:6:11) at fromFileUrl (file:///$HOME/$WORKSPACE/node_modules/.pnpm/@jsr+std__path@1.1.4/node_modules/@jsr/std__path/posix/from_file_url.js:18:9) at basename (file:///$HOME/$WORKSPACE/node_modules/.pnpm/@jsr+std__path@1.1.4/node_modules/@jsr/std__path/posix/basename.js:45:12) ``` This applies to `@std/path/basename` as well. If instead of using a URL object, the .href is used directly as a string, the basename is returned correctly. **Expected behavior** The basename to work regardless of the protocol. **Actual behavior** ``` Uncaught TypeError: URL must be a file URL: received "https:" at assertArg (file:///$HOME/$WORKSPACE/node_modules/.pnpm/@jsr+std__path@1.1.4/node_modules/@jsr/std__path/_common/from_file_url.js:6:11) at fromFileUrl (file:///$HOME/$WORKSPACE/node_modules/.pnpm/@jsr+std__path@1.1.4/node_modules/@jsr/std__path/posix/from_file_url.js:18:9) at basename (file:///$HOME/$WORKSPACE/node_modules/.pnpm/@jsr+std__path@1.1.4/node_modules/@jsr/std__path/posix/basename.js:45:12) ``` **Environment** - OS: macOS Tahoe 26.2 - deno version: v2.7.14 - std version: 1.1.4
3 条评论