Skip to content

Commit

Permalink
Resolve #100. XDG paths have to be absolute
Browse files Browse the repository at this point in the history
Morally revert b9d0d69
  • Loading branch information
phadej committed Dec 24, 2019
1 parent 9084797 commit 4ae67c1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Contributions and bug reports are welcome!

Please remember to add changelog entries.
4 changes: 2 additions & 2 deletions System/Directory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,8 +1532,8 @@ getXdgDirectory xdgDir suffix =
XdgConfig -> "XDG_CONFIG_HOME"
XdgCache -> "XDG_CACHE_HOME"
case env of
Nothing -> getXdgDirectoryFallback getHomeDirectory xdgDir
Just path -> pure path
Just path | isAbsolute path -> pure path
_ -> getXdgDirectoryFallback getHomeDirectory xdgDir

-- | Similar to 'getXdgDirectory' but retrieves the entire list of XDG
-- directories.
Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog for the [`directory`][1] package
==========================================

## 1.3.5.0 (December 2019)

* Revert change introduced in the version `1.3.2.2`:
Non-absolute `XDG_*` environment variables are ignored.
This behavior is according to *XDG Base Directory Specification*
version 0.7, https://specifications.freedesktop.org/basedir-spec/0.7/ar01s02.html
([#100](https://github.com/haskell/directory/issues/100))

## 1.3.4.0 (July 2019)

* `getXdgDirectory` and `getXdgDirectoryList` on Windows will now respect
Expand Down
3 changes: 1 addition & 2 deletions directory.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: directory
version: 1.3.4.0
-- NOTE: Don't forget to update ./changelog.md
version: 1.3.5.0
license: BSD3
license-file: LICENSE
maintainer: libraries@haskell.org
Expand Down
20 changes: 16 additions & 4 deletions tests/Xdg.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ module Xdg where
#if MIN_VERSION_base(4, 7, 0)
import qualified Data.List as List
import System.Environment (setEnv, unsetEnv)
import System.FilePath ((</>), searchPathSeparator)
import System.FilePath (searchPathSeparator)
#if !defined(mingw32_HOST_OS)
import System.FilePath ((</>))
#endif
#endif
#include "util.inl"

Expand All @@ -24,12 +27,21 @@ main _t = do
T(expectEq) () (home </> ".config/mow") =<< getXdgDirectory XdgConfig "mow"
#endif

-- unset variables, so env doesn't affect test running
unsetEnv "XDG_DATA_HOME"
unsetEnv "XDG_CONFIG_HOME"
unsetEnv "XDG_CACHE_HOME"
xdgData <- getXdgDirectory XdgData "ff"
xdgConfig <- getXdgDirectory XdgConfig "oo"
xdgCache <- getXdgDirectory XdgCache "rk"

-- non-absolute paths are ignored, and the fallback is used
setEnv "XDG_DATA_HOME" "ar"
setEnv "XDG_CONFIG_HOME" "aw"
setEnv "XDG_CACHE_HOME" "ba"
T(expectEq) () ("ar" </> "ff") =<< getXdgDirectory XdgData "ff"
T(expectEq) () ("aw" </> "oo") =<< getXdgDirectory XdgConfig "oo"
T(expectEq) () ("ba" </> "rk") =<< getXdgDirectory XdgCache "rk"
T(expectEq) () xdgData =<< getXdgDirectory XdgData "ff"
T(expectEq) () xdgConfig =<< getXdgDirectory XdgConfig "oo"
T(expectEq) () xdgCache =<< getXdgDirectory XdgCache "rk"

unsetEnv "XDG_CONFIG_DIRS"
unsetEnv "XDG_DATA_DIRS"
Expand Down

0 comments on commit 4ae67c1

Please sign in to comment.