2

I know absolute path-only URLs (/path/to/resource) are valid, and refer to the same scheme, host, port, etc. as the current resource. Is the URL still valid if the same (or a different!) scheme is added? (http:/path/to/resource or https:/path/to/resource)

If it is valid according to the letter of the spec, how well do browsers handle it? How well do developers that may come across the code in the future handle it?

Addendum:

Here's a simple test case I set up on an Apache server:

resource/number/one/index.html:

<a href="http:/resource/number/two/">link</a>

resource/number/two/index.html:

two

Testing in Chrome 43 on OS X: The URL displayed when hovering over the link looks correct. Clicking the link works as expected. Looking at the DOM in the web inspector, hovering over the a href URL displays an incorrect location (/resource/number/one/http:/resource/number/two/).

Firefox 38 appears to also handle the click correctly. Weird.

unor
  • 92,415
  • 26
  • 211
  • 360
smitelli
  • 6,835
  • 3
  • 31
  • 53
  • @minitech Chrome 43 seemed to handle it, although that was more of an accidental discovery than an exhaustive test. – smitelli Jul 15 '15 at 19:58
  • I’m using Chromium 43 right now and it definitely doesn’t work. `http:/path/to/resource` goes to `http://path/to/resource`. – Ry- Jul 15 '15 at 20:00
  • @minitech Weird! My tests showed the exact opposite. See the addendum on my question. – smitelli Jul 15 '15 at 20:27
  • 1
    Just to be clear, what you call the "incorrect location" is actually the *correct* location. – EricLaw Jul 17 '15 at 19:39
  • @EricLaw: Well, it’s not valid, so really the browser can decide to do whatever it wants with it. And apparently, it does. – Ry- Jul 17 '15 at 21:19
  • @EricLaw: No, it really isn’t valid; see my answer, and specifically the last paragraph of quoted text. (If it were valid, the browser would also treat it consistently.) – Ry- Jul 23 '15 at 17:44

1 Answers1

3

No, it’s not valid. From RFC 3986:

4.2.  Relative Reference

   A relative reference takes advantage of the hierarchical syntax
   (Section 1.2.3) to express a URI reference relative to the name space
   of another hierarchical URI.

      relative-ref  = relative-part [ "?" query ] [ "#" fragment ]

      relative-part = "//" authority path-abempty
                    / path-absolute
                    / path-noscheme
                    / path-empty

   The URI referred to by a relative reference, also known as the target
   URI, is obtained by applying the reference resolution algorithm of
   Section 5.

   A relative reference that begins with two slash characters is termed
   a network-path reference; such references are rarely used.  A
   relative reference that begins with a single slash character is
   termed an absolute-path reference.  A relative reference that does
   not begin with a slash character is termed a relative-path reference.

   A path segment that contains a colon character (e.g., "this:that")
   cannot be used as the first segment of a relative-path reference, as
   it would be mistaken for a scheme name.  Such a segment must be
   preceded by a dot-segment (e.g., "./this:that") to make a relative-
   path reference.

where path-noscheme is specifically a path that doesn’t start with / whose first segment does not contain a colon, which addresses your question pretty specifically.

Community
  • 1
  • 1
Ry-
  • 218,210
  • 55
  • 464
  • 476
  • According to spec these are structurally valid URIs, but would make invalid links because relative authority (domain name in this case) would be considered empty (5.2.2). Browsers resolve them differently due to historical reasons (5.4.2), but some consistency would be nice. – shudder Jan 05 '18 at 00:30