web: allow single- or double-quoted filter patterns containing spaces

This commit is contained in:
Simon Michael 2010-12-05 20:11:55 +00:00
parent dbba128f29
commit 6aff8134b6

View File

@ -16,6 +16,7 @@ import Data.Either
-- import System.Directory -- import System.Directory
import System.FilePath ((</>), takeFileName) import System.FilePath ((</>), takeFileName)
import System.IO.Storage (putValue, getValue) import System.IO.Storage (putValue, getValue)
import Text.ParserCombinators.Parsec hiding (string)
import Database.Persist.GenericSql (ConnectionPool, SqlPersist, runMigration, migrate) import Database.Persist.GenericSql (ConnectionPool, SqlPersist, runMigration, migrate)
import Yesod import Yesod
@ -268,10 +269,17 @@ getHandlerData = do
a <- fromMaybe "" <$> lookupGetParam "a" a <- fromMaybe "" <$> lookupGetParam "a"
p <- fromMaybe "" <$> lookupGetParam "p" p <- fromMaybe "" <$> lookupGetParam "p"
let opts = appOpts app ++ [Period p] let opts = appOpts app ++ [Period p]
args = appArgs app ++ words a args = appArgs app ++ words' a
fspec = optsToFilterSpec opts args t fspec = optsToFilterSpec opts args t
return (a, p, opts, fspec) 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 -- | 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 -- error while reloading, keep the old one and return the error, and set a
-- ui message. -- ui message.