Permalink
Browse files

Made resource root more robust, added test

  • Loading branch information...
1 parent 7f3cdee commit 4fd00aa58df774d83a89cd341bf09aebc926ab04 @weavejester weavejester committed Jul 6, 2010
Showing with 7 additions and 2 deletions.
  1. +2 −2 ring-core/src/ring/util/response.clj
  2. +5 −0 ring-core/test/ring/util/response_test.clj
View
4 ring-core/src/ring/util/response.clj
@@ -60,8 +60,8 @@
Options:
:root - take the resource relative to this root"
[path & [opts]]
- (let [opts (apply hash-map opts)
- path (str (opts :root "") path)
+ (let [path (str (:root opts "") "/" path)
+ path (.replace path "//" "/")
loader (clojure.lang.RT/baseLoader)]
(if-let [resource (.getResourceAsStream loader path)]
(response resource))))
View
5 ring-core/test/ring/util/response_test.clj
@@ -25,5 +25,10 @@
(is (.startsWith (slurp* (resp :body))
"(ns ring.util.response-test"))))
+(deftest test-resource-with-root
+ (let [resp (resource-response "response_test.clj" {:root "/ring/util"})]
+ (is (.startsWith (slurp* (resp :body))
+ "(ns ring.util.response-test"))))
+
(deftest test-missing-resource
(is (nil? (resource-response "/missing/resource.clj"))))

0 comments on commit 4fd00aa

Please sign in to comment.