Skip to content

Commit

Permalink
Better error reporting on invalid cookie attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Nov 14, 2011
1 parent bbd36d0 commit 2e6fd50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ring-core/src/ring/middleware/cookies.clj
Expand Up @@ -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."
Expand Down Expand Up @@ -118,7 +119,7 @@
(update-in response
[:headers "Set-Cookie"]
concat
(write-cookies cookies))
(doall (write-cookies cookies)))
response))

(defn wrap-cookies
Expand Down
5 changes: 5 additions & 0 deletions ring-core/test/ring/middleware/test/cookies.clj
Expand Up @@ -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.