NET-A-PORTER/scala-uri

Trailing slashes are not normalized

Closed this issue · 3 comments

cb372 commented
val base = readFromConfigFile()  // "http://www.example.com/"
val uri = base / "search"
uri.toString  // "http://www.example.com//search"

Is this expected behaviour? Personally, I expected the library to take care of this for me, i.e. normalize the double slash into a single slash. It would be great if there was at least an option to allow this.

theon commented

RFC-3986 does have a section on Normalization and Comparison, and we have not implemented any of it yet in scala-uri.

The spec does specifically reference empty path segments and does say they can be collapsed for http:

because the "http" scheme makes use of an authority component, has a default port of "80", and defines an empty path to be equivalent to "/", the following four URIs are equivalent:

 http://example.com
 http://example.com/
 http://example.com:/
 http://example.com:80/

So, sounds like a good shout to me!

@theon That says that an empty path is equivalent to /, not that an empty path segment can be collapsed. I've worked on a bunch of (varying levels of crazy) systems which depended on multiple slash characters in sequence being distinguishable in HTTP.

theon commented

Ah yes, good catch. I misead that. In that case I don't think we should do this kind of normalisation. We can open another ticket for the collapsing of . and .. path segments which is described in the spec.