From 545c0911aa5d7d91280c5213c6d57b3e634ef1e5 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Mon, 17 Jan 2022 19:53:26 -0800
Subject: [PATCH] T.P.App.Opt: fix logic bug in fullDefaultsPath.

Previously we would (also) search the default user data directory
for a defaults file, even if a different user data directory
was specified using `--data-dir`.  This was a mistake; if
`--data-dir` is used, the default user data directory should
not be searched.
---
 src/Text/Pandoc/App/Opt.hs | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
index 4f5474c4f..2b3494022 100644
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -707,9 +707,10 @@ fullDefaultsPath dataDir file = do
   let fp = if null (takeExtension file)
               then addExtension file "yaml"
               else file
-  defaultDataDir <- liftIO defaultUserDataDir
-  let defaultFp = fromMaybe defaultDataDir dataDir </> "defaults" </> fp
-  fromMaybe fp <$> findM fileExists [fp, defaultFp]
+  let searchpath = fp : case dataDir of
+                          Nothing -> []
+                          Just d  -> [d </> "defaults" </> fp]
+  fromMaybe fp <$> findM fileExists searchpath
 
 -- | In a list of lists, append another list in front of every list which
 -- starts with specific element.