8

On some input we allow the following paths:

I wonder if I can mark them all as "URI"s?

Thanks!

Powerslave
  • 351
  • 1
  • 3
  • 13

2 Answers2

11

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.

stybl
  • 8,580
  • 3
  • 24
  • 48
1

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).

Community
  • 1
  • 1
Boris
  • 7,044
  • 6
  • 62
  • 63