From 40d70ad10b3e66fb31b86d83e4b905370b5d7724 Mon Sep 17 00:00:00 2001 From: Joseph Weston Date: Thu, 2 Aug 2018 08:38:56 +0200 Subject: [PATCH] lib: fail when file to include is in stack of 'include' files --- hledger-lib/Hledger/Read/JournalReader.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 32825b883..773454a72 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -216,6 +216,10 @@ includedirectivep = do else parseErrorAt parserpos $ "No existing files match pattern: " ++ filename parseChild parentpos filepath = do + parentfilestack <- fmap sourceName . statePos <$> getParserState + when (filepath `elem` parentfilestack) + $ parseErrorAt parentpos ("Cyclic include: " ++ filepath) + childInput <- lift $ readFilePortably filepath `orRethrowIOError` (show parentpos ++ " reading " ++ filepath)