Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

url: pathToFileURL duplicates root slash across platforms and misses empty extended UNC servername

クローズ 初心者向け
#67,091 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@JoaoMarcos44 がすでに取り組んでいます。

2026年10月28日 から。

  • #67092 @JoaoMarcos44 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js
領域
api, backend

調査の方向性

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:

  1. Cross-platform root path trailing slash duplication (resolved[resolved.length - 1] !== path.sep):
    When restoring trailing slashes stripped by path.resolve(), pathToFileURL() compares the last character of resolved against the host platform's path.sep instead 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:/')
    
  2. Extended UNC path empty servername bypass (hostnameEndIndex === 2):
    For extended UNC paths (\\?\UNC\...), prefixLength is 8, but the empty servername check hardcodes if (hostnameEndIndex === 2) instead of if (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 }).href should return 'file:///' on all platforms (including Windows).
  • url.pathToFileURL('C:\\', { windows: true }).href and url.pathToFileURL('C:/', { windows: true }).href should return 'file:///C:/' on all platforms (including POSIX).
  • url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }) should throw ERR_INVALID_ARG_VALUE (Empty UNC servername), matching url.pathToFileURL('\\\\\\share', { windows: true }).
What do you see instead?
  • url.pathToFileURL('/', { windows: false }).href on Windows returns 'file:////'.
  • url.pathToFileURL('C:\\', { windows: true }).href on POSIX returns 'file:///C://'.
  • url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }).href returns 'file:///share'.
Additional information

In lib/internal/url.js:

  • Line 1707 checks if (hostnameEndIndex === 2) instead of if (hostnameEndIndex === prefixLength).
  • Line 1722 checks resolved[resolved.length - 1] !== path.sep instead of resolved[resolved.length - 1] !== (windows ? '\\' : '/').
主要言語
JavaScript
スター
123k
フォーク
39.3k
平均マージ
4日 11時間
マージ済み PR(30日)
237

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nodejs/node のほかの issue

nodejs/node の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。