Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 0e31fa59edc2043f713ca57f9bb735fb2a4ad8f2 1 parent 358c701
@weavejester weavejester authored
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}))))
Please sign in to comment.
Something went wrong with that request. Please try again.