node
node copied to clipboard
Possible bug in node:internal/url getpathfromurlwin32
Version
16.15.1
Platform
Microsoft Windows NT 10.0.19045.0 x64
Subsystem
url
What steps will reproduce the bug?
This might be a bug in v8 rather than node's url
module, but I'm reporting here first since I'm not sufficiently knowledgeable in C++ or with the URL spec to determine if the bug is in v8 or where it is.
On networked filesystems on Windows, v8's Profiler.takePreciseCoverage
ends up returning URLs that are of the form file:////some-server-cifs/<path-to-js-file>
. While the URL appears to have 'too many' slashes, Chrome and Windows Explorer are perfectly happy to resolve this. However, node throws some errors.
On Windows, create a file, test.mjs
, that contains:
import { fileURLToPath } from 'url'
const url = 'file:////some-server-cifs/vmgr/17/testdir/foo.txt'
const p = fileURLToPath(url)
Now run node test.mjs
.
How often does it reproduce? Is there a required condition?
The code provided will reproduce this issue every time on Windows
What is the expected behavior? Why is that the expected behavior?
I would expect either v8 to return valid URLs or NodeJS' url.fileURLToPath()
to sanitize the "slightly malformed" URL and parse it correctly just like Chrome and Windows Explorer do.
What do you see instead?
node:internal/errors:465
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
at new NodeError (node:internal/errors:372:5)
at getPathFromURLWin32 (node:internal/url:1393:11)
at fileURLToPath (node:internal/url:1423:22)
at file:///S:/test.mjs:4:11
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12) {
code: 'ERR_INVALID_FILE_URL_PATH'
}
Additional information
If it is deemed that there is some kind of bug in NodeJS regarding this, I'm hoping url.fileURLToPath
can handle this gracefully.
FWIW, python3 is also perfectly happy to handle this URL
from urllib import request
data = request.urlopen('file:////some-server-cifs/vmgr/17/testdir/foo.txt')
for line in data:
print(line)