fix-recursive-includes
Fix recursive includes beyond depth 3. Also add a test case for the bug.
This commit is contained in:
parent
1a8353457d
commit
5e576e9ff0
@ -77,4 +77,4 @@ expandPath pos fp = liftM mkRelative (expandHome fp)
|
|||||||
| otherwise = return inname
|
| otherwise = return inname
|
||||||
|
|
||||||
fileSuffix :: FilePath -> String
|
fileSuffix :: FilePath -> String
|
||||||
fileSuffix = reverse . takeWhile (/='.') . reverse . dropWhile (/='.')
|
fileSuffix = reverse . takeWhile (/='.') . reverse . dropWhile (/='.')
|
||||||
|
|||||||
@ -123,6 +123,7 @@ import Text.ParserCombinators.Parsec hiding (parse)
|
|||||||
import Prelude hiding (readFile, putStr, putStrLn, print, getContents)
|
import Prelude hiding (readFile, putStr, putStrLn, print, getContents)
|
||||||
import System.IO.UTF8
|
import System.IO.UTF8
|
||||||
#endif
|
#endif
|
||||||
|
import System.FilePath
|
||||||
import Hledger.Data.Utils
|
import Hledger.Data.Utils
|
||||||
import Hledger.Data.Types
|
import Hledger.Data.Types
|
||||||
import Hledger.Data.Dates
|
import Hledger.Data.Dates
|
||||||
@ -214,7 +215,7 @@ ledgerInclude = do many1 spacenonewline
|
|||||||
outerPos <- getPosition
|
outerPos <- getPosition
|
||||||
let inIncluded = show outerPos ++ " in included file " ++ show filename ++ ":\n"
|
let inIncluded = show outerPos ++ " in included file " ++ show filename ++ ":\n"
|
||||||
return $ do contents <- expandPath outerPos filename >>= readFileE outerPos
|
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 ++))
|
Right l -> l `catchError` (throwError . (inIncluded ++))
|
||||||
Left perr -> throwError $ inIncluded ++ show perr
|
Left perr -> throwError $ inIncluded ++ show perr
|
||||||
where readFileE outerPos filename = ErrorT $ liftM Right (readFile filename) `catch` leftError
|
where readFileE outerPos filename = ErrorT $ liftM Right (readFile filename) `catch` leftError
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
# nested includes in subdirectories
|
# 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
|
2010/01/01
|
||||||
(A) 1
|
(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
|
2010/01/01
|
||||||
(C) 1
|
(C) 1
|
||||||
|
|
||||||
|
2010/01/01
|
||||||
|
(D) 1
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user