From 490a46fcd27d007a8477bd73ca4b2f021b2ed070 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 2 May 2024 07:26:12 -1000 Subject: [PATCH] fix: journal: parse include directives with trailing whitespace [https://github.com/adept/full-fledged-hledger/issues/29] --- hledger-lib/Hledger/Read/JournalReader.hs | 2 +- hledger/test/journal/include.test | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index ac7a8a0f9..13c976d5c 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -291,7 +291,7 @@ includedirectivep :: MonadIO m => ErroringJournalParser m () includedirectivep = do string "include" lift skipNonNewlineSpaces1 - prefixedglob <- T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet + prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet parentoff <- getOffset parentpos <- getSourcePos let (mprefix,glb) = splitReaderPrefix prefixedglob diff --git a/hledger/test/journal/include.test b/hledger/test/journal/include.test index ad4443707..65bd490d1 100644 --- a/hledger/test/journal/include.test +++ b/hledger/test/journal/include.test @@ -54,14 +54,19 @@ $ hledger -f - print >2 // >= 1 -# ** 5. include nonexsitant file +# ** 5. include nonexistent file < include doesnotexist.journal $ hledger -f - print >2 // >= 1 -# ** 6. include relative to home +# ** 6. trailing whitespace after the filename does not make a file nonexistent +< +include a.timeclock +$ hledger -f - check + +# ** 7. include relative to home < include ~/included.journal $ printf '2018/01/01\n (A) 1\n' >included.journal; HOME="$PWD" hledger -f - print; rm -rf included.journal @@ -73,17 +78,17 @@ $ printf '2018/01/01\n (A) 1\n' >included.journal; HOME="$PWD" hledger -f - pr # The next tests require hard coded file names, so are not concurrent-safe. # They use different file names so a single concurrent shelltest invocation will be fine. -# ** 7. test that order of include files is maintained +# ** 8. test that order of include files is maintained $ printf 'include _b\n' >_a; touch _b; hledger -f _a stats -v | grep _ | sed -e 's%.*/%%'; rm -rf _a _b _a _b -# ** 8. and with --auto code path +# ** 9. and with --auto code path $ printf 'include _d\n=\n' >_c; touch _d; hledger -f _c stats -v --auto | grep _ | sed -e 's%.*/%%'; rm -rf _c _d _c _d -# ** 9. include using old !include directive +# ** 10. include using old !include directive < !include f.journal $ printf '2018/01/01\n (A) 1\n' >f.journal; hledger -f - print; rm -f f.journal