Permalink
Browse files

Better error reporting on invalid cookie attributes

  • Loading branch information...
1 parent bbd36d0 commit 2e6fd5086ce187874827e68a1fba024051fda615 @weavejester weavejester committed Nov 14, 2011
Showing with 9 additions and 3 deletions.
  1. +4 −3 ring-core/src/ring/middleware/cookies.clj
  2. +5 −0 ring-core/test/ring/middleware/test/cookies.clj
@@ -88,8 +88,9 @@
(defn- valid-attr?
"Is the attribute valid?"
- [[_ value]]
- (not (.contains (str value) ";")))
+ [[key value]]
+ (and (contains? set-cookie-attrs key)
+ (not (.contains (str value) ";"))))
(defn- write-attr-map
"Write a map of cookie attributes to a string."
@@ -118,7 +119,7 @@
(update-in response
[:headers "Set-Cookie"]
concat
- (write-cookies cookies))
+ (doall (write-cookies cookies)))
response))
(defn wrap-cookies
@@ -78,3 +78,8 @@
resp ((wrap-cookies handler) {})]
(is (= {"Set-Cookie" (list "a=b" "c=d")}
(:headers resp)))))
+
+(deftest wrap-cookies-invalid-attrs
+ (let [response {:cookies {"a" {:value "foo" :invalid true}}}
+ handler (wrap-cookies (constantly response))]
+ (is (thrown? AssertionError (handler {})))))

0 comments on commit 2e6fd50

Please sign in to comment.