-
Notifications
You must be signed in to change notification settings - Fork 476
Closed
Labels
Description
Given a URI like this:
URI("http://www.example.org/foo/bar/bat");
it’s difficult to programmatically append a trailing slash.
I thought this might work, but it doesn’t:
URI("http://www.example.org/foo/bar/bat")
.segment("")
.toString();
// -> "http://www.example.org/foo/bar/bat" :(
This is annoying when you’re constructing a path using successive calls to .segment()
or .segmentCoded()
:
function apiUri(category, name) {
var baseUri = URI("http://www.example.org/api/")
return baseUri.segmentCoded(category)
.segmentCoded(name)
.segment("");
}
apiUri("furniture", "hatstand").toString();
// -> "http://www.example.org/api/furniture/hatstand"
// but we wanted "http://www.example.org/api/furniture/hatstand/"
// with trailing slash :(
I’m not sure of the best way to solve this problem, but it seems like segment("")
would make sense as a way to add a trailing slash to an existing URI.
After all, it would be consistent with the behaviour of the .segment()
getter:
URI("http://www.example.org/foo/bar/bat/").segment();
// -> ["foo", "bar", "bat", ""]