Fork me on GitHub
#pedestal
<
2016-10-19
>
rauh10:10:22

So url-for-routes omits trailing / which are part of my URL. Is this intentional or a bug?

mtnygard14:10:30

@rauh Interesting... I think that has to do with the path parsing. The trailing / probably gets turned into an empty string in the route's :path-parts. Running a check to verify that now.

mtnygard14:10:47

@rauh Nope, I was wrong. The trailing slash gets elided completely when parsing the route. So by the time you call url-for-routes, there's nothing there to represent that slash.

rauh14:10:49

@mtnygard If it matters: I'm using the new/fast MapRouter

mtnygard14:10:16

I don't think that matters, but I will double-check.

mtnygard14:10:05

OK, so I just confirmed. The router doesn't affect url-for-routes. Which route syntax are you using?

rauh15:10:41

((router/url-for-routes
   (table/table-routes
     [["/api/"
       :get identity
       :route-name :x]]))
  :x)
;; => "/api"

mtnygard15:10:43

I would bet that matches on both “/api/“ and “/api"

rauh15:10:55

Nope, 404's

mtnygard15:10:25

Can you paste the value that table/table-routes returns?

rauh15:10:42

=> ({:path "/api/", :method :get, :path-re #"/\Qapi\E", :path-parts ["api"], :interceptors [#Interceptor{:name }], :route-name :x, :path-params []})

mtnygard15:10:52

OK, now I see what’s going on. The map-tree router uses :path to match, whereas the prefix-tree and linear-search use :path-re

mtnygard15:10:07

But url-for-routes reconstructs the path from :path-parts.

mtnygard15:10:21

I’d definitely call this a bug.

rauh15:10:31

I see. Thanks for checking, should I report?

mtnygard15:10:05

I can’t think of a workaround at the moment. How important is that trailing slash to you? 🙂

rauh16:10:39

I just wrapped it and added a slash 🙂

rauh16:10:47

Not important, only for my tests...