TooTallNate / file-uri-to-path

Convert a `file:` URI to a file path
MIT License
27 stars 8 forks source link

"file:" schema not supported, only recognises "file://" (with an empty authority) as a valid file URI #7

Open jhoag opened 6 years ago

jhoag commented 6 years ago

The definition of a URI is:
scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment] (https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#URL_and_URN)

So the // is optional. At the moment, the validation fails unless the slashes are included.

Expected Any URI starting with "file:" is accepted

Actual URIs are rejected unless they begin"file://"

This is causing issues when using this library in a system with URIs produced by other libraries.

xmedeko commented 4 years ago

The validation should strip any number of slashes after file:. Consider everything after file: as a path and OS/app may accept any number of slashes at the path start. Even if it's not correct, many apps accept that (e.g. MS Windows), so a user may enter such URI and we want to handle that, too.

xmedeko commented 4 years ago

I see Node.js has a function url.fileURLToPath since v10.12.0.