From 015dacb0d7171e13f5bd9ed6efde95d798be8e1f Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 4 Jan 2012 11:35:39 +0000 Subject: [PATCH] web: add form should reject blank account names (#81) --- hledger-web/Hledger/Web/Handlers.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hledger-web/Hledger/Web/Handlers.hs b/hledger-web/Hledger/Web/Handlers.hs index 4e813ccb1..893f3fe90 100644 --- a/hledger-web/Hledger/Web/Handlers.hs +++ b/hledger-web/Hledger/Web/Handlers.hs @@ -14,6 +14,7 @@ import Data.Either (lefts,rights) import Data.List import Data.Maybe import Data.Text(Text,pack,unpack) +import qualified Data.Text (null) import Data.Time.Calendar import Data.Time.Clock import Data.Time.Format @@ -472,8 +473,9 @@ handleAdd = do -- supply defaults and parse date and amounts, or get errors. let dateE = maybe (Left "date required") (either (\e -> Left $ showDateParseError e) Right . fixSmartDateStrEither today . unpack) dateM descE = Right $ maybe "" unpack descM - acct1E = maybe (Left "to account required") (Right . unpack) acct1M - acct2E = maybe (Left "from account required") (Right . unpack) acct2M + maybeNonNull = maybe Nothing (\t -> if Data.Text.null t then Nothing else Just t) + acct1E = maybe (Left "to account required") (Right . unpack) $ maybeNonNull acct1M + acct2E = maybe (Left "from account required") (Right . unpack) $ maybeNonNull acct2M amt1E = maybe (Left "amount required") (either (const $ Left "could not parse amount") Right . parseWithCtx nullctx someamount . unpack) amt1M amt2E = maybe (Right missingamt) (either (const $ Left "could not parse amount") Right . parseWithCtx nullctx someamount . unpack) amt2M journalE = maybe (Right $ journalFilePath j)