From ef22b131f156943f36cf757e56c9f7f648352324 Mon Sep 17 00:00:00 2001 From: James Parker Date: Tue, 31 Jan 2017 15:25:44 -0500 Subject: [PATCH 1/2] Fix for bug in identifyForm with empty forms. #1072 --- yesod-form/Yesod/Form/Functions.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/yesod-form/Yesod/Form/Functions.hs b/yesod-form/Yesod/Form/Functions.hs index fc1e9903a..73e260600 100644 --- a/yesod-form/Yesod/Form/Functions.hs +++ b/yesod-form/Yesod/Form/Functions.hs @@ -62,7 +62,7 @@ import Yesod.Core import Yesod.Core.Handler (defaultCsrfParamName) import Network.Wai (requestMethod) import Text.Hamlet (shamlet) -import Data.Monoid (mempty) +import Data.Monoid (mempty, (<>)) import Data.Maybe (listToMaybe, fromMaybe) import qualified Data.Map as Map import qualified Data.Text.Encoding as TE @@ -336,13 +336,13 @@ identifyForm identVal form = \fragment -> do -- Create hidden . let fragment' = [shamlet| - + #{fragment} |] -- Check if we got its value back. mp <- askParams - let missing = (mp >>= Map.lookup identifyFormKey) /= Just [identVal] + let missing = (mp >>= Map.lookup identifyFormKey) /= Just ["identify-" <> identVal] -- Run the form proper (with our hidden ). If the -- data is missing, then do not provide any params to the @@ -350,7 +350,10 @@ identifyForm identVal form = \fragment -> do -- doing this avoids having lots of fields with red errors. let eraseParams | missing = local (\(_, h, l) -> (Nothing, h, l)) | otherwise = id - eraseParams (form fragment') + ( res', w) <- eraseParams (form fragment') + + let res = if missing then FormMissing else res' + return ( res, w) identifyFormKey :: Text identifyFormKey = "_formid" From d59344b78b9a5be1d45d72911a53820173e7a571 Mon Sep 17 00:00:00 2001 From: James Parker Date: Thu, 2 Feb 2017 01:55:00 -0500 Subject: [PATCH 2/2] housekeeping --- yesod-form/ChangeLog.md | 4 ++++ yesod-form/Yesod/Form/Functions.hs | 1 + yesod-form/yesod-form.cabal | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/yesod-form/ChangeLog.md b/yesod-form/ChangeLog.md index fdd3f56c5..58731e1c0 100644 --- a/yesod-form/ChangeLog.md +++ b/yesod-form/ChangeLog.md @@ -1,3 +1,7 @@ +## 1.4.10 + +* Fixed `identifyForm` to properly return `FormMissing` for empty forms. [#1072](https://github.com/yesodweb/yesod/issues/1072) + ## 1.4.9 * Added a `ToValue` instance for `Enctype` [#1296](https://github.com/yesodweb/yesod/pull/1296) diff --git a/yesod-form/Yesod/Form/Functions.hs b/yesod-form/Yesod/Form/Functions.hs index 73e260600..ed83624f0 100644 --- a/yesod-form/Yesod/Form/Functions.hs +++ b/yesod-form/Yesod/Form/Functions.hs @@ -352,6 +352,7 @@ identifyForm identVal form = \fragment -> do | otherwise = id ( res', w) <- eraseParams (form fragment') + -- Empty forms now properly return FormMissing. [#1072](https://github.com/yesodweb/yesod/issues/1072) let res = if missing then FormMissing else res' return ( res, w) diff --git a/yesod-form/yesod-form.cabal b/yesod-form/yesod-form.cabal index bd5296e6f..9f8a31de7 100644 --- a/yesod-form/yesod-form.cabal +++ b/yesod-form/yesod-form.cabal @@ -1,5 +1,5 @@ name: yesod-form -version: 1.4.9 +version: 1.4.10 license: MIT license-file: LICENSE author: Michael Snoyman