Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a (local) file path a URI?

Tags:

url

path

uri

On some input we allow the following paths:

  • C:\Folder
  • \\server\Folder
  • http://example.com/...

Can I mark them all as "URI"s?

like image 565
Powerslave Avatar asked Jun 22 '17 07:06

Powerslave


People also ask

What is local file path?

A local path is the path to a folder or file on your local computer (e.g. C:\Program Files\Sitebulb). A UNC path is the path to a folder or file on a network and contains the server name in the path (e.g. \\server01\sitebulb\path).

Is a path an URL?

A URL (Uniform Resource Locator) identifies a resource on a remote server and gives the network location on that server. The URL path is the string of information that comes after the top level domain name. You can use the HTTP-proxy to block websites that contain specified text in the URL path.

Can a URI be a relative path?

URIs are always absolute (unless they're relative URIs, which is a different beast without a schema). That comes from them being a server-client technology where referencing the server's working directory doesn't make sense.


2 Answers

C:/Folder and /server/Folder/ are file paths.

http://example.com/ is a URL, which is a URI sub-type, so you could mark it as a URI but not the other way around (like how squares are rectangles but not vice versa).

Of course, here you have posted a clear, simple example. When discussing the distinction between URI and URL, not only is the answer not clear cut, it is also disputed. I recommend taking a look at this thread and the answers posted in it for clarification. Generally though, it is mostly agreed that the main difference is that URLs provide an access method (such as http://).

So if we were to convert your first file path into a URL it would become the following (note the addition of the access method):

file:///c:/Folder/test.txt

If you modify all your file paths to include an access method like in my example, then it will be okay for you to mark them as URIs.

like image 71
stelioslogothetis Avatar answered Sep 18 '22 17:09

stelioslogothetis


Strictly speaking no, unless you make sure it's an absolute path and add add "file://" to the beginning.

As per RFC 3986 Section 3:

URI         = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

hier-part   = "//" authority path-abempty
            / path-absolute
            / path-rootless
            / path-empty

The scheme and the ":" are not in square brackets [], which means they are not optional.

However, the HTML standard calls these "path-relative-scheme-less-URL strings" and they're valid in the href attribute of an HTML element so maybe it's fine to call relative Unix paths "URLs" (not absolute Unix paths or Windows paths though).

like image 41
Boris Avatar answered Sep 20 '22 17:09

Boris