fix-recursive-includes

Fix recursive includes beyond depth 3. Also add a test case for the bug.
This commit is contained in:
Ben Boeckel 2010-09-02 00:30:57 +00:00
parent 1a8353457d
commit 5e576e9ff0
3 changed files with 7 additions and 3 deletions

View File

@ -123,6 +123,7 @@ import Text.ParserCombinators.Parsec hiding (parse)
import Prelude hiding (readFile, putStr, putStrLn, print, getContents)
import System.IO.UTF8
#endif
import System.FilePath
import Hledger.Data.Utils
import Hledger.Data.Types
import Hledger.Data.Dates
@ -214,7 +215,7 @@ ledgerInclude = do many1 spacenonewline
outerPos <- getPosition
let inIncluded = show outerPos ++ " in included file " ++ show filename ++ ":\n"
return $ do contents <- expandPath outerPos filename >>= readFileE outerPos
case runParser journalFile outerState filename contents of
case runParser journalFile outerState (combine ((takeDirectory . sourceName) outerPos) filename) contents of
Right l -> l `catchError` (throwError . (inIncluded ++))
Left perr -> throwError $ inIncluded ++ show perr
where readFileE outerPos filename = ErrorT $ liftM Right (readFile filename) `catch` leftError

View File

@ -1,5 +1,5 @@
# nested includes in subdirectories
mkdir -p b/c ; printf '2010/1/1\n (C) 1\n' >b/c/c.journal ; printf '2010/1/1\n (B) 1\n!include c/c.journal\n' >b/b.journal ; printf '2010/1/1\n (A) 1\n!include b/b.journal\n' >a.journal ; hledger -f a.journal print; rm -rf b
mkdir -p b/c/d ; printf '2010/1/1\n (D) 1\n' >b/c/d/d.journal ; printf '2010/1/1\n (C) 1\n!include d/d.journal\n' >b/c/c.journal ; printf '2010/1/1\n (B) 1\n!include c/c.journal\n' >b/b.journal ; printf '2010/1/1\n (A) 1\n!include b/b.journal\n' >a.journal ; hledger -f a.journal print; rm -rf b
>>>
2010/01/01
(A) 1
@ -10,3 +10,6 @@ mkdir -p b/c ; printf '2010/1/1\n (C) 1\n' >b/c/c.journal ; printf '2010/1/1\n
2010/01/01
(C) 1
2010/01/01
(D) 1