-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Support url *strings* in fs APIs #17658
Comments
I'm fine with it if it's shown that performance of fs APIs given regular path strings does not decrease because of this. Checking for a URL object is much simpler than checking for the first 7 characters, though I agree that having to reparse URLs is a hassle. I also understand that accepting URL objects is not recommended by the URL Standard in the first place. |
We discussed this in the original PR a bit (at first, it contained support for that): #10739 (comment) |
It looks like it was backed out of the original PR for security concerns.
Will try to assemble that background once I’m back at a real computer.
…On Wed, Dec 13, 2017 at 10:11 AM Timothy Gu ***@***.***> wrote:
I'm fine with it if it's shown that performance of fs APIs given regular
path strings does not decrease because of this. Checking for a URL object
is much simpler than checking for the first 7 characters, though I agree
that having to reparse URLs is a hassle. I also understand that accepting
URL objects is not recommended
<https://url.spec.whatwg.org/#url-apis-elsewhere> by the URL Standard in
the first place.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#17658 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAio9AcnF0AqTJEeWcrpjCuq4CGTeZqtks5tABNZgaJpZM4RA83e>
.
|
There are a couple of issues here:
At this point I'm -1 on modifying the existing APIs further to support this case, tho I would not be opposed to alternate methods that support it. e.g., instead of |
Interesting. I agree that continuously overloading the meaning of the existing APIs isn't great. Originally I had something like "only if the string starts exactly with 'file://'" which might address the performance or existing filename concerns. Still, leaves the security concerns and a potentially confusing API ("here's the 20 different things that might be passed in as a filename"). I could see |
I've already got an effort under way to work up some Promise-based fs APIs. The PR has been sitting there for a bit without updating, but it will be advancing. There are definitely going to be some differences between it and the current API so I'm weighing just how much different it should be. |
Thanks, I'll have a look at #15485! |
The real issue IMO, is that this is simply incorrect. Files may contain If it's a string, it should be treated as a path. If it's a URL, it should be treated as a URL. |
@pauldraper's comment is a dealbreaker for me: $ mkdir -p file\:/abc
$ echo 'hello world' > file\:/abc/abc
$ node
> fs.readFileSync('file:///abc/abc', 'utf8')
'hello world\n' I'm going to close this as something that can't reasonably be accomplished. |
Right now the FS APIs do support URLs - but only if they are passed as URL objects. This seems to go against the use of URLs in DOM APIs where methods tend to accept strings. E.g.
fetch
only "accepts" URL objects because they happen to stringify to their.href
property.Would it be acceptable to extend the current support for file URLs to "any string starting with
file://
will be treated like a URL object"? This would remove the need for people to manually create import and then instantiate a URL object if they already have a valid file URL (e.g. viaimport.meta.url
).The text was updated successfully, but these errors were encountered: