- ++ FilePath.Posix.joinPath (r : FilePath.splitDirectories p)
-
- stripVarPrefix var (root:path')
- | Just [sep] <- stripPrefix var root
- , isPathSeparator sep
- = Just (joinPath path')
-
- stripVarPrefix _ _ = Nothing
+ ++ FilePath.Posix.joinPath
+ (r : -- We need to drop a leading "/" or "\\"
+ -- if there is one:
+ dropWhile (all isPathSeparator)
+ (FilePath.splitDirectories p))
+
+ -- We could drop the separator here, and then use </> above. However,
+ -- by leaving it in and using ++ we keep the same path separator
+ -- rather than letting FilePath change it to use \ as the separator
+ stripVarPrefix var path = case stripPrefix var path of
+ Just [] -> Just []
+ Just cs@(c : _) | isPathSeparator c -> Just cs
+ _ -> Nothing