[commit: packages/filepath] master: Insert slash when first argument to joinDrive does not end with one (c986cde)
git at git.haskell.org
git at git.haskell.org
Thu Mar 19 11:35:10 UTC 2015
Repository : ssh://git@git.haskell.org/filepath
On branch : master
Link : http://git.haskell.org/packages/filepath.git/commitdiff/c986cde979992074dabda71088474630f459cd13
>---------------------------------------------------------------
commit c986cde979992074dabda71088474630f459cd13
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date: Thu Oct 23 18:23:56 2014 +0200
Insert slash when first argument to joinDrive does not end with one
Before:
joinDrive "/foo" "bar" == "/foobar"
After:
joinDrive "/foo" "bar" == "/foo/bar"
The first argument to `joinDrive` should arguably always be a drive. On Posix
this means it should be, and thus end with, a single slash. It is currently
undocumented what should happen when it doesn't end with a slash (throw an
exception?). Since it is unlikely anyone is relying on the original behavior,
this change is hopefully ok to make.
The reason for this change is to make `joinDrive` similar in semantics to
`combineAlways`.
>---------------------------------------------------------------
c986cde979992074dabda71088474630f459cd13
System/FilePath/Internal.hs | 5 ++---
changelog.md | 3 +++
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index e48d01b..1e2cdc9 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -383,12 +383,11 @@ readDriveShareName name = addSlash a b
-- > Windows: joinDrive "\\\\share" "foo" == "\\\\share\\foo"
-- > Windows: joinDrive "/:" "foo" == "/:\\foo"
joinDrive :: FilePath -> FilePath -> FilePath
-joinDrive a b | isPosix = a ++ b
- | null a = b
+joinDrive a b | null a = b
| null b = a
| hasTrailingPathSeparator a = a ++ b
| otherwise = case a of
- [a1,':'] | isLetter a1 -> a ++ b
+ [a1,':'] | isWindows && isLetter a1 -> a ++ b
_ -> a ++ [pathSeparator] ++ b
-- | Get the drive from a filepath.
diff --git a/changelog.md b/changelog.md
index b037c48..f79c011 100644
--- a/changelog.md
+++ b/changelog.md
@@ -4,6 +4,9 @@
* Bundled with GHC 7.10.1
+ * Semantic change: `joinDrive "/foo" "bar"` now returns `"/foo/bar"`,
+ instead of `"/foobar"`.
+
* Bug fix: `isDrive ""` now retuns `False`, instead of `True`.
* Bug fix: on Windows, `dropTrailingPathSeparator "/"` now returns `"/"`
More information about the ghc-commits
mailing list