Skip to content

url: skip resolve for already-absolute POSIX paths - #41

Open
anonrig wants to merge 1 commit into
mainfrom
cursor/url-path-fast-ead2
Open

anonrig wants to merge 1 commit into
mainfrom
cursor/url-path-fast-ead2

Conversation

@anonrig

@anonrig anonrig commented Sep 22, 2026

Copy link
Copy Markdown
Owner

pathToFileURL always called path.resolve, even when the input was already an absolute POSIX path with no . / .. or empty // segments. Reuse that path. Windows UNC and relative paths still go through path.resolve.

Official benchmark/url/whatwg-url-to-and-from-path.js (--no-node-snapshot, 4 alternating runs vs parent):

method input change
pathToFileURL /dev/null +27%
pathToFileURL /dev/null?key=param&bool +48%
pathToFileURL /dev/null?key=param&bool#hash +45%
pathToFileURL file:///dev/null (relative path string) ~0%
fileURLToPath file:///dev/null ~0%

test/parallel/test-url-pathtofileurl.js and test-url-fileurltopath.js pass. A closed-source coding agent assisted with the implementation.

Open in Web Open in Cursor 

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4520770. Configure here.

Comment thread lib/internal/url.js Outdated
StringPrototypeIndexOf(filepath, '.') === -1 &&
StringPrototypeIndexOf(filepath, '//') === -1) {
// Already an absolute POSIX path with no '.' / '..' or empty segments.
resolved = filepath;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Trailing slashes doubled on Windows

Medium Severity

Skipping path.resolve keeps a trailing slash on already-absolute POSIX paths. The later restore still appends another slash when resolved does not end with path.sep. On Windows, path.sep is a backslash, so pathToFileURL with windows: false emits a double slash and a wrong file: URL for directory paths.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4520770. Configure here.

pathToFileURL always called path.resolve, even when the input was
already an absolute POSIX path with no '.' / '..' or empty
segments. Reuse that path and drop a trailing slash the same way
posix.resolve does, so the later restore does not append a second
slash when path.sep is '\' (Windows host, windows: false).

Official benchmark/url/whatwg-url-to-and-from-path.js
pathToFileURL is about 27% faster for /dev/null and about 45-48%
faster when the path has a query or hash. fileURLToPath is
unchanged.

Assisted-by: a closed-source coding agent
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/url-path-fast-ead2 branch from c663b90 to ca37e8f Compare September 22, 2026 06:32
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.

1 participant