-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Node.js APIs are inconvenient to use with URL strings #48994
Copy link
Copy link
Closed as not planned
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.pathIssues and PRs related to the path subsystem.Issues and PRs related to the path subsystem.staleurlIssues and PRs related to the legacy built-in url module.Issues and PRs related to the legacy built-in url module.
Metadata
Metadata
Assignees
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.pathIssues and PRs related to the path subsystem.Issues and PRs related to the path subsystem.staleurlIssues and PRs related to the legacy built-in url module.Issues and PRs related to the legacy built-in url module.
Problem
Spinning off from #48740 (comment), many of our APIs such as
fs.readFileaccept URL instances (what you get fromnew URL) but not URL strings (likeimport.meta.url, or the return value of the soon-to-be-unflaggedimport.meta.resolve). In the case of many (all?) of these, all strings are interpreted as paths. This is frustrating since in ESM, we have easy access to URL strings such asimport.meta.urlbut path strings require using helpers such asfileURLToPath.Original Idea
Wherever feasible, all Node.js APIs that can accept URL strings should do so. In particular this is most relevant to the
fsAPIs, especially the ones that already accept URL instances. To avoid ambiguity with path strings, such APIs should only interpret URL strings that begin withfile:.I presume that this would be a semver-major change, to avoid needing to first check for the existence of a file or folder named
file:in the local path; or perhaps we could add such a check now in order to land this and backport it, and remove such a check in a semver major.We would also need to consider the security implications. Per @aduh95:
I don’t really see how this is a security concern, but I concede that there might be issues to consider. Perhaps some can be addressed via permissions or policies. I do feel however that since URL strings are so prevalent in ESM, we should require a high bar for security concerns to outweigh usability for this feature.
cc @nodejs/loaders @nodejs/modules @nodejs/security