1

On my Windows 10 machine I can enter a file URL of a local directory (e.g. file:///D:/temp), or a local file (e.g. file:///D:/temp/homepage.html) and everything works fine.

However, wherever there is a forward slash in those valid URLs, I can insert many more, and everything still works fine. For example:

file:///D://///////////////////temp///////////////MiscTests///////

Also see the screenshot from Chrome:

At first I thought this was a bug in Chrome, but Opera, Edge and Firefox also do the same thing so I assume that the URL is perfectly valid.

As a related issue, it's worth noting that those browsers also allow multiple slashes in a web URL (e.g. https:///////////////////www.amazon.com), though in that scenario the URL in the address bar gets corrected to https://www.amazon.com. So it's not just file URLs that allow many slashes.

Is there a good reason for the browsers allowing all those slashes, or is it an oversight in some specification that can't be corrected?

3

RFC3986, section 3.3 says multiple slashes are valid in URLs.

The / in a URL determines where segments of the URL are split. A double slash (outside the authority delimiter, which is the first //) would yield an empty segment, which according to RFC 2396 may be ignored. Technically a webserver could throw an exception on this, but users expect webservers to handle this sort of thing, so it just ignores it.

Btw, this also happens on Unices (which the web was arguably modeled after):

The Single Unix specification section 3.266 defines that multiple slashes can be considered as one:

A character string that is used to identify a file. In the context of IEEE Std 1003.1-2001, a pathname consists of, at most, {PATH_MAX} bytes, including the terminating null byte. It has an optional beginning slash, followed by zero or more filenames separated by slashes. A pathname may optionally contain one or more trailing slashes. Multiple successive slashes are considered to be the same as one slash.

  • Thanks for those references. RFC2396 was superseded by RFC3986, but section 3.3 of that document ("Path") confirms that multiple slashes are valid. – skomisa Jan 18 '18 at 1:49
  • Thanks for the correction. I've updated my answer. – mtak Jan 18 '18 at 7:34
  • Where does RFC 3986 say that it "may be ignored"? I didn’t find it in section 3.3. – unor Jan 18 '18 at 13:43
  • @unor On closer reading, RFC3986 3.3 doesn't actually say anything about multiple slashes in the path. However, the definition of 'path-absolute' in App. A (Collected ABNF for URI), and the sample regex in App. B (Parsing a URI Reference with a Regular Expression), both allow for multiple slashes. – skomisa Jan 18 '18 at 17:48
  • @skomisa: Yes, multiple / are allowed without a doubt, but so are multiple a, multiple 2 etc. -- they all change the meaning of the URL, unless the contrary is listed in the spec. So the question is why file URLs work anyway -- my guess (but nothing more) is that the OS decides, i.e., how the file pathes work (like described in mtak’s quote from the Unix spec, for example). (Why HTTP URLs with multiple slashes work is a different matter: this depends on the server, i.e., some make these URLs point to the same resource, some redirect to a canonical form, some give errors etc.) – unor Jan 18 '18 at 18:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.