From 3775552d87e83bbeefed325f1f81681876607a13 Mon Sep 17 00:00:00 2001 From: Luite Stegeman Date: Tue, 13 Mar 2012 11:19:16 +0100 Subject: [PATCH] improve nonce key code as per @gregwebs' suggestion --- yesod-core/Yesod/Internal/Request.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/yesod-core/Yesod/Internal/Request.hs b/yesod-core/Yesod/Internal/Request.hs index e477e900..56e7f916 100644 --- a/yesod-core/Yesod/Internal/Request.hs +++ b/yesod-core/Yesod/Internal/Request.hs @@ -79,10 +79,12 @@ parseWaiRequest' env session' useNonce gen = -- nonceKey present in the session is ignored). If sessions -- are enabled and a session has no nonceKey a new one is -- generated. - nonce = case (useNonce, lookup nonceKey session') of - (False, _) -> Nothing - (_, Just x) -> Just $ decodeUtf8With lenientDecode x - _ -> Just $ pack $ randomString 10 gen + nonce = if not useNonce + then Nothing + else Just $ maybe + (pack $ randomString 10 gen) + (decodeUtf8With lenientDecode) + (lookup nonceKey session') addTwoLetters :: ([Text] -> [Text], Set.Set Text) -> [Text] -> [Text] addTwoLetters (toAdd, exist) [] =