From a409d0943557a51540f158b0eb50d5094bc5a30e Mon Sep 17 00:00:00 2001 From: Alex Chen Date: Wed, 9 May 2018 22:40:33 -0600 Subject: [PATCH] lib: restrict backtracking when parsing postings (#747) --- hledger-lib/Hledger/Read/JournalReader.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index a42d7be81..40bb5110b 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -581,7 +581,7 @@ test_transactionp = do -- Parse the following whitespace-beginning lines as postings, posting -- tags, and/or comments (inferring year, if needed, from the given date). postingsp :: MonadIO m => Maybe Day -> ErroringJournalParser m [Posting] -postingsp mdate = many (try $ postingp mdate) "postings" +postingsp mdate = many (postingp mdate) "postings" -- linebeginningwithspaces :: Monad m => JournalParser m String -- linebeginningwithspaces = do @@ -593,10 +593,12 @@ postingsp mdate = many (try $ postingp mdate) "postings" postingp :: MonadIO m => Maybe Day -> ErroringJournalParser m Posting postingp mtdate = do -- pdbg 0 "postingp" - lift (skipSome spacenonewline) - status <- lift statusp - lift (skipMany spacenonewline) - account <- modifiedaccountnamep + (status, account) <- try $ do + lift (skipSome spacenonewline) + status <- lift statusp + lift (skipMany spacenonewline) + account <- modifiedaccountnamep + return (status, account) let (ptype, account') = (accountNamePostingType account, textUnbracket account) amount <- spaceandamountormissingp massertion <- partialbalanceassertionp