From 6aff8134b60ff11a74ecb2c234d92bb6db702043 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 5 Dec 2010 20:11:55 +0000 Subject: [PATCH] web: allow single- or double-quoted filter patterns containing spaces --- hledger-web/Hledger/Web/App.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hledger-web/Hledger/Web/App.hs b/hledger-web/Hledger/Web/App.hs index abd07da3c..fedfd4f4f 100644 --- a/hledger-web/Hledger/Web/App.hs +++ b/hledger-web/Hledger/Web/App.hs @@ -16,6 +16,7 @@ import Data.Either -- import System.Directory import System.FilePath ((), takeFileName) import System.IO.Storage (putValue, getValue) +import Text.ParserCombinators.Parsec hiding (string) import Database.Persist.GenericSql (ConnectionPool, SqlPersist, runMigration, migrate) import Yesod @@ -268,10 +269,17 @@ getHandlerData = do a <- fromMaybe "" <$> lookupGetParam "a" p <- fromMaybe "" <$> lookupGetParam "p" let opts = appOpts app ++ [Period p] - args = appArgs app ++ words a + args = appArgs app ++ words' a fspec = optsToFilterSpec opts args t return (a, p, opts, fspec) + -- | Quote-sensitive words, ie don't split on spaces which are inside quotes. + words' :: String -> [String] + words' = fromparse . parsewith ((quotedPattern <|> pattern) `sepBy` many1 spacenonewline) + where + pattern = many (noneOf " \n\r\"") + quotedPattern = between (oneOf "'\"") (oneOf "'\"") $ many $ noneOf "'\"" + -- | Update our copy of the journal if the file changed. If there is an -- error while reloading, keep the old one and return the error, and set a -- ui message.