url: pathToFileURL duplicates root slash across platforms and misses empty extended UNC servername
維護者通常 1 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, node.js
研究方向
從 issue 指出的 lib/internal/url.js 中兩處位置開始,接著閱讀周圍的 pathToFileURL() 邏輯和相關 URL 測試。使用 { windows: false } 和 { windows: true } 重現根斜線案例,並檢查現有測試如何涵蓋空的延伸 UNC 伺服器名稱。完成條件是跨平台 URL 結尾只有一個斜線,而且空伺服器名稱會擲出 ERR_INVALID_ARG_VALUE。
由索引模型根據 Issue 內容生成。
描述
Version
v22.16.0 (also reproduces on main)
Platform
Microsoft Windows NT 10.0.26100.0 x64 (and POSIX platforms when passing `{ windows: true }`)
Subsystem
url
What steps will reproduce the bug?
url.pathToFileURL() has two bugs in lib/internal/url.js:
-
Cross-platform root path trailing slash duplication (
resolved[resolved.length - 1] !== path.sep):
When restoring trailing slashes stripped bypath.resolve(),pathToFileURL()compares the last character ofresolvedagainst the host platform'spath.sepinstead of the target separator (windows ? '\\' : '/'):// On Windows (where path.sep === '\\'): console.log(url.pathToFileURL('/', { windows: false }).href); // Prints: 'file:////' (4 slashes instead of 'file:///') // On POSIX / Linux / macOS (where path.sep === '/'): console.log(url.pathToFileURL('C:\\', { windows: true }).href); // Prints: 'file:///C://' (double trailing slash instead of 'file:///C:/') -
Extended UNC path empty servername bypass (
hostnameEndIndex === 2):
For extended UNC paths (\\?\UNC\...),prefixLengthis8, but the empty servername check hardcodesif (hostnameEndIndex === 2)instead ofif (hostnameEndIndex === prefixLength):console.log(url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }).href); // Prints: 'file:///share' instead of throwing ERR_INVALID_ARG_VALUE ('Empty UNC servername')
How often does it reproduce? Is there a required condition?
Always (100% reproducible).
What is the expected behavior? Why is that the expected behavior?
url.pathToFileURL('/', { windows: false }).hrefshould return'file:///'on all platforms (including Windows).url.pathToFileURL('C:\\', { windows: true }).hrefandurl.pathToFileURL('C:/', { windows: true }).hrefshould return'file:///C:/'on all platforms (including POSIX).url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true })should throwERR_INVALID_ARG_VALUE(Empty UNC servername), matchingurl.pathToFileURL('\\\\\\share', { windows: true }).
What do you see instead?
url.pathToFileURL('/', { windows: false }).hrefon Windows returns'file:////'.url.pathToFileURL('C:\\', { windows: true }).hrefon POSIX returns'file:///C://'.url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }).hrefreturns'file:///share'.
Additional information
In lib/internal/url.js:
- Line 1707 checks
if (hostnameEndIndex === 2)instead ofif (hostnameEndIndex === prefixLength). - Line 1722 checks
resolved[resolved.length - 1] !== path.sepinstead ofresolved[resolved.length - 1] !== (windows ? '\\' : '/').
- 主要語言
- JavaScript
- 星號
- 123k
- 分支
- 39.3k
- 平均合併
- 4 天 11 小時
- 30 天內合併 PR
- 237
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
node:internal/inspector/network_http: `TypeError: Missing dataLength` in event when response uses `setEncoding()`可能已有人在做 @lazerg 於 23 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
[Docs] `process.loadEnvFile()` does not document behaviour when variables already exist可能已有人在做 @Sepandard 於 33 天前認領。 未關閉doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
Stream.prototype.forEach will block in first promise in queue before read more chunk可能已有人在做 @mmustafasenoglu 於 34 天前認領。 未關閉doc
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
nodejs 26.8.2 fails to build with clang/LLVM可能重新可做 @btyagi18 於 20 天前認領,目前沒有進行中的 PR。 未關閉build
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
相似的 Issue
-
FEATURE REQUEST
難度 2/5 1-3 小時 新手友好度 68/100
linuxmint/cinnamon-spices-extensions#1193 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
Fei2411/DeepSeek-Bot#703 ·
-
area:web first-timers-only good first issue
難度 1/5 1 小時以內 新手友好度 95/100
career-ops-hq/career-ops#6264 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 74/100
catppuccin/firefox#21 ·
-
難度 1/5 1 小時以內 新手友好度 83/100
cline/mcp-marketplace#3394 ·