Tuesday, May 03, 2022
I'm hoping this is a joke, because if it's not, I'm not sure what that says about our society
I finished my lunch of a sub sandwich when I notice a message printed on the wrapper in not-so-small print:
I have no words.
The legality of double slashes in URIs
Martin Chang replied to my musings on processing malformed Gemini requests, saying that double slashes in URIs are illegal, and pointed out the ABNF grammar from the URI specification to back up his claim:
path = path-absolute ; begins with "/" but not "//" path-absolute = "/" [ segment-nz *( "/" segment ) ] segment-nz = 1*pchar pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
But he didn't quote the segment
rule:
segment = *pchar
which translated says,
“0 or more pchar
rules.”
So the ABNF he quoted does indeed rule out //boston/2018/07/04.2
.
It doesn't rule out /boston//2018/07/04.2
,
since by the time we hit the double slash,
we're in the *( "/" segment )
part of the path-absolute
rule,
and segment
can have 0 characters.
But what he quoted only applies to relative links,
what I receive is an abolute link.
If you follow the ABNF from that perspective:
URI-reference = URI / relative-ref URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] hier-part = "//" authority path-abempty / path-absolute / path-rootless / path-empty path-abempty = *( "/" segment ) ; other rules omitted
not only does this allow gemini://gemini.conman.org//boston/2018/07/04.2
but gemini://gemini.conman.org///////////boston/2018/07/04.2
.
I can understand why this was done—to simplify the grammar as the various path-
rules generally end with *( "/" segment )
allows one to end a URI with a trailing slash or not.
I don't think the intent was to allow long strings of slashes,
but that's the end result of a lax grammar.
Martin is also correct that multiple slashes are treated as a single slash on POSIX
(basically,
any Unix system),
that's not the case across all operating systems.
One exception I can think of AmigaOS,
where each slash represents a parent directory.
This command, cd ///
on AmigaOS is the same as cd ‥/‥/‥
on a POSIX system.
Crazy,
I know.
And maybe not even relevant these days,
but I thought I should mention it.