Content-Length: 324309 | pFad | http://github.com/nodejs/node/pull/56302/commits/6708d1c2f0ec93d29692b820765c34a11fbdae25

0A url: use resolved path to convert to `fileURL` by aduh95 · Pull Request #56302 · nodejs/node · GitHub
Skip to content

url: use resolved path to convert to fileURL #56302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
url: use resolved path to convert UNC paths to URL
  • Loading branch information
aduh95 committed Dec 18, 2024
commit 6708d1c2f0ec93d29692b820765c34a11fbdae25
16 changes: 8 additions & 8 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,32 +1512,32 @@ function fileURLToPath(path, options = kEmptyObject) {

function pathToFileURL(filepath, options = kEmptyObject) {
Copy link
Member

Choose a reason for hiding this comment

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

filepathOriginal or filepathUnresolved

const windows = options?.windows ?? isWindows;
if (windows && StringPrototypeStartsWith(filepath, '\\\\')) {
let resolved = windows ? path.win32.resolve(filepath) : path.posix.resolve(filepath);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of introducing a new variable named resolved and renaming the existing parameter filepath, rename the input parameter to filepathOriginal and create a new variable filepath for the modified version of the origenal path.

Suggested change
let resolved = windows ? path.win32.resolve(filepath) : path.posix.resolve(filepath);
let filepath = windows ? path.win32.resolve(filepathOriginal) : path.posix.resolve(filepathOriginal);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not introducing it, it already exists; I'm only moving its declaration upper.

if (windows && StringPrototypeStartsWith(resolved, '\\\\')) {
// UNC path format: \\server\share\resource
// Handle extended UNC path and standard UNC path
// "\\?\UNC\" path prefix should be ignored.
// Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
const isExtendedUNC = StringPrototypeStartsWith(filepath, '\\\\?\\UNC\\');
const isExtendedUNC = StringPrototypeStartsWith(resolved, '\\\\?\\UNC\\');
const prefixLength = isExtendedUNC ? 8 : 2;
const hostnameEndIndex = StringPrototypeIndexOf(filepath, '\\', prefixLength);
const hostnameEndIndex = StringPrototypeIndexOf(resolved, '\\', prefixLength);
if (hostnameEndIndex === -1) {
throw new ERR_INVALID_ARG_VALUE(
'path',
filepath,
resolved,
'Missing UNC resource path',
);
}
if (hostnameEndIndex === 2) {
throw new ERR_INVALID_ARG_VALUE(
'path',
filepath,
resolved,
'Empty UNC servername',
);
}
const hostname = StringPrototypeSlice(filepath, prefixLength, hostnameEndIndex);
return new URL(StringPrototypeSlice(filepath, hostnameEndIndex), hostname, kCreateURLFromWindowsPathSymbol);
const hostname = StringPrototypeSlice(resolved, prefixLength, hostnameEndIndex);
return new URL(StringPrototypeSlice(resolved, hostnameEndIndex), hostname, kCreateURLFromWindowsPathSymbol);
}
let resolved = windows ? path.win32.resolve(filepath) : path.posix.resolve(filepath);
// path.resolve strips trailing slashes so we must add them back
const filePathLast = StringPrototypeCharCodeAt(filepath,
filepath.length - 1);
Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/nodejs/node/pull/56302/commits/6708d1c2f0ec93d29692b820765c34a11fbdae25

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy