File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 208208 (subs path 0 (- (count path) (count suffix))))
209209
210210(defn- if-context [route handler]
211- (fn [request]
212- (if-let [params (clout/route-matches route request)]
213- (let [uri (:uri request)
214- path (:path-info request uri)
215- context (or (:context request) " " )
216- subpath (:__path-info params)
217- params (dissoc params :__path-info )]
218- (handler
219- (-> request
220- (assoc-route-params (decode-route-params params))
221- (assoc :path-info (if (= subpath " " ) " /" subpath)
222- :context (remove-suffix uri subpath))))))))
211+ (if (#{" :__path-info" " /:__path-info" } (:source route))
212+ handler
213+ (fn [request]
214+ (if-let [params (clout/route-matches route request)]
215+ (let [uri (:uri request)
216+ path (:path-info request uri)
217+ context (or (:context request) " " )
218+ subpath (:__path-info params)
219+ params (dissoc params :__path-info )]
220+ (handler
221+ (-> request
222+ (assoc-route-params (decode-route-params params))
223+ (assoc :path-info (if (= subpath " " ) " /" subpath)
224+ :context (remove-suffix uri subpath)))))))))
223225
224226(defn- context-route [route]
225227 (let [re-context {:__path-info #"|/.*" }]
Original file line number Diff line number Diff line change 214214 request (mock/request :get " /emote/%5C%3F%2F" ) ]
215215 (is (= (-> request handler :body ) " \\ ?/" ))
216216 (is (= (-> request cxt-handler :body ) " \\ ?/" ))
217- (is (= (-> request in-cxt-handler :body ) " \\ ?/" )))))
217+ (is (= (-> request in-cxt-handler :body ) " \\ ?/" ))))
218+
219+ (testing " root context"
220+ (let [handler (context " /" []
221+ (GET " /" [] " root" )
222+ (GET " /foo" [] " foo" )
223+ (GET " /foo/:x" [x] x))]
224+ (are [url body] (= (:body (handler (mock/request :get url)))
225+ body)
226+ " /" " root"
227+ " /foo" " foo"
228+ " /foo/2" " 2" ))))
218229
219230(deftest let-routes-test
220231 (let [handler (let-routes [a " foo" , b " bar" ]
You can’t perform that action at this time.
0 commit comments