Skip to content

Tricky to construct a path with trailing slash #106

djcsdy opened this Issue Aug 13, 2013 · 5 comments

2 participants

djcsdy commented Aug 13, 2013

Given a URI like this:


it’s difficult to programmatically append a trailing slash.

I thought this might work, but it doesn’t:

// -> "" :(

This is annoying when you’re constructing a path using successive calls to .segment() or .segmentCoded():

function apiUri(category, name) {
    var baseUri = URI("")
    return baseUri.segmentCoded(category)

apiUri("furniture", "hatstand").toString();
// -> ""
// but we wanted ""
// 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:

// -> ["foo", "bar", "bat", ""]
Medialize member

Yeah, I'm not sure I'm happy with segment() returning an empty-string element in that array. But for consistency, .segment("") should add an empty element, if the last element isn't empty - agreed. Are you already looking into this, or should I have a go at it?

djcsdy commented Aug 13, 2013

No, I won’t have time to do anything about this for a few days at least.

For the time being I’m working around the problem by doing this for the last segment:


which is pretty horrible :)

Medialize member

… my eyes!

Medialize member

if this fixes your problem, I'd release a new version tonight/tomorrow…

@rodneyrehm rodneyrehm closed this Aug 13, 2013
djcsdy commented Aug 13, 2013

Yep, that fixes it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.