Skip to content

Replace deprecated url.parse in uriToFilePath with WHATWG URL - #1926

Open
Trivikram Kamat (trivikr) wants to merge 6 commits into
microsoft:mainfrom
trivikr:server-url-parse
Open

Trivikram Kamat (trivikr) wants to merge 6 commits into
microsoft:mainfrom
trivikr:server-url-parse

Conversation

@trivikr

@trivikr Trivikram Kamat (trivikr) commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

url.parse is deprecated in Node.js. This PR replaces it in Files.uriToFilePath with the WHATWG URL API.

  • Use new URL(uri).pathname instead of url.parse(uri).path. The rest of the decoding and Windows drive-letter handling stays the same.
  • If URL can't parse the input, the function returns undefined, as it did before.
  • Query strings are no longer included in the returned path. For example, file:///a/b.ts?q=1 now gives /a/b.ts.

There are no existing tests for uriToFilePath, and none were added since the function is deprecated.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The URI parsing change can resolve existing file URIs to the wrong file because new URL() normalizes .. segments before percent-decoding.

1 open issue

Review effort: Balanced

Comment thread server/src/node/files.ts Resolved
Copilot AI balanced review requested due to automatic review settings October 30, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The URI extraction regresses Windows file URI handling by skipping preprocessing, causing literal backslashes and surrounding whitespace to produce undefined results or incorrect filenames.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread server/src/node/files.ts Resolved
@dbaeumer

Copy link
Copy Markdown
Member

Trivikram Kamat (@trivikr) see copilot review again.

And you don't need to request a review. It is automatically done when a change is pushed.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 16:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@trivikr

Copy link
Copy Markdown
Contributor Author

Trivikram Kamat (Trivikram Kamat (@trivikr)) see copilot review again.

Fixed by trimming the input and converting backslashes before extracting the path in d45f703

And you don't need to request a review. It is automatically done when a change is pushed.

I didn't request it manually. The review request was added automatically.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Authority-only file URIs incorrectly return undefined instead of preserving their implicit root path, causing a regression for valid inputs such as file://localhost.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve implicit root path for authority-only file URIs

server/​src/​node/​files.ts:28

Authority-only file URIs lose their implicit root path here. For example, file://localhost and file://localhost#fragment previously returned / on POSIX, but this regex captures an empty path and the following guard returns undefined, even though new URL() accepts both with pathname /. Preserve the implicit / for a nonempty authority while continuing to use the raw path when one is present.

1 resolved since last review

Review effort: Balanced

@dbaeumer

Copy link
Copy Markdown
Member

Trivikram Kamat (@trivikr) see copilot review

Copilot AI balanced review requested due to automatic review settings November 3, 2026 16:09
@trivikr

Copy link
Copy Markdown
Contributor Author

Authority-only file URIs incorrectly return undefined instead of preserving their implicit root path, causing a regression for valid inputs such as file://localhost.

Fixed in 5f9f0e1 (this PR)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Using trim() removes Unicode whitespace previously preserved as filename data, causing affected file URLs to point to a different file.

1 open issue

Review effort: Balanced

Comment thread server/src/node/files.ts Resolved
Use `new URL(uri).pathname` instead of `url.parse(uri).path`. Input
that URL can't parse still returns undefined. Query strings are no
longer included in the returned file path.
URL.pathname resolves '..' segments before percent-decoding, so
file:///tmp/one%2Ftwo/../three.ts mapped to /tmp/three.ts instead of
/tmp/one/three.ts. Take the raw path from the URI string so segments
are decoded before path.normalize, as url.parse did.
Taking the raw path from the URI string skipped preprocessing that
url.parse did: file://localhost\C:\work\a.ts returned undefined,
leading whitespace returned undefined, and trailing whitespace stayed
in the path. Trim the input and convert backslashes to forward slashes
before extracting the path.
When a file URI has an authority but no path, such as file://localhost
or file://localhost#frag, return '/' as url.parse did. Previously the
raw path regex captured an empty string and returned undefined. URIs
with an empty authority (file://, file:) still return undefined.
String.prototype.trim() strips Unicode whitespace such as U+2003 that
url.parse kept as part of the filename, and leaves C0 control
characters that url.parse removed. Trim only C0 controls, space,
U+00A0 and U+FEFF so the resolved paths match the old behavior.
Copilot AI balanced review requested due to automatic review settings November 5, 2026 05:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The URL constructor runs before legacy-compatible trimming, causing file URLs with leading U+00A0 or U+FEFF to return undefined instead of their previously resolved paths.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread server/src/node/files.ts Resolved
WHATWG URL does not trim leading U+00A0 or U+FEFF, so inputs such as
"\u00A0file:///tmp/a.ts" threw and returned undefined, while url.parse
returned /tmp/a.ts. Trim and convert backslashes before constructing
the URL, and use the same normalized string for the raw path.
Copilot AI balanced review requested due to automatic review settings November 5, 2026 05:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to weigh unpublished findings involving changed file-URI path semantics and quadratic whitespace normalization that can block the server’s event loop.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants