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で特定されている2か所の lib/internal/url.js から始め、その周辺の pathToFileURL() のロジックと関連するURLテストを読みます。{ windows: false } と { windows: true } を使ってルートスラッシュのケースを再現し、既存のテストが空の拡張UNCサーバー名をどのようにカバーしているか確認します。クロスプラットフォームURLの末尾にスラッシュが1つだけ付き、空のサーバー名が 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時間
- マージ済み PR(30日)
- 237
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
nodejs/node#66551 · コメント 1 件 ·
メンテナーはふだん 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 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbuild
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
nodejs/node#66076 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
[Feature Request] [Web] Expose kvCacheQuantizationBits in the onnxruntime-web WebGPU EP optionsオープンep:WebGPU platform:web quantization
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
microsoft/onnxruntime#33752 ·
メンテナーはふだん 2 日以内に返信
-
icon request
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
tabler/tabler-icons#1693 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
alvarotrigo/fullPage.js#4755 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
jlab-sensing/ENTS-backend#854 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
andromarces/agent-loops#1242 ·
メンテナーはふだん 1 日以内に返信