Skip to content
Browse files

Fixed flash to not wipe out session if session is not set in response

  • Loading branch information...
1 parent 358c701 commit 0e31fa59edc2043f713ca57f9bb735fb2a4ad8f2 @weavejester weavejester committed Jul 4, 2010
Showing with 16 additions and 3 deletions.
  1. +4 −3 ring-core/src/ring/middleware/flash.clj
  2. +12 −0 ring-core/test/ring/middleware/flash_test.clj
View
7 ring-core/src/ring/middleware/flash.clj
@@ -15,6 +15,7 @@
:flash flash)
response (handler request)
session (if-let [flash (response :flash)]
- (assoc (response :session) :_flash flash)
- session)]
- (assoc response :session session))))
+ (assoc (response :session session) :_flash flash))]
+ (if (or session (contains? response :session))
+ (assoc response :session session)
+ response))))
View
12 ring-core/test/ring/middleware/flash_test.clj
@@ -22,3 +22,15 @@
response (handler {:session {:_flash message}})]
(is (nil? (:flash response)))
(is (nil? (-> response :session :_flash)))))
+
+(deftest flash-doesnt-wipe-session
+ (let [message {:error "Could not save"}
+ handler (wrap-flash (constantly {:flash message}))
+ response (handler {:session {:foo "bar"}})]
+ (is (= (:session response) {:foo "bar", :_flash message}))))
+
+(deftest flash-overwrites-nil-session
+ (let [message {:error "Could not save"}
+ handler (wrap-flash (constantly {:flash message, :session nil}))
+ response (handler {:session {:foo "bar"}})]
+ (is (= (:session response) {:_flash message}))))

0 comments on commit 0e31fa5

Please sign in to comment.
Something went wrong with that request. Please try again.