Conversation
When passing a path like "F:/foo/bar" on windows
(both '/' and '\' are valid path separators on windows)
we'll get garbage output like so:
> mkPathNative "F:/foo/bar"
"F:/foo/bar"
> unPathNative "F:/foo/bar"
"F:foo\\bar"
...effectively turning an absolute path into a relative path
("F:foo\\bar" on windows is the directory "foo\\bar"
relative to the current working directory on drive F).
This is because Posix and Windows splitDirectories behave differently:
> System.FilePath.Posix.splitDirectories $ "F:/foo/bar"
["F:","foo","bar"]
> System.FilePath.Windows.splitDirectories $ "F:/foo/bar"
["F:/","foo","bar"]
When joining paths on windows, the filepath library does not
assume a trailing path separator after the drive (here "F:").
This is because as described above, "F:foo" is valid relative
filepath.
|
To trigger the bug on windows: Resulting in: |
|
Discussion:
|
|
@andreabedini ran into this bug while working on stable-haskell/ghc#135 |
andreasabel
left a comment
There was a problem hiding this comment.
Thanks for the PR!
Backslash path separators are indeed a pest to be stomped out.
| -------------------------------------------------------------------------------} | ||
|
|
||
| prop_mkPathNative :: Property | ||
| prop_mkPathNative = property $ \(fp :: FilePath) -> (mkPathNative . unPathNative . mkPathNative) fp === mkPathNative fp |
There was a problem hiding this comment.
Since FilePath = String, how likely is an interesting test generated here?
Maybe it would be good to add a few unit tests.
There was a problem hiding this comment.
Filepath has a windows path BNF that's used to generate interesting output, but that would be some copy pasta: https://github.com/haskell/filepath/blob/master/tests/filepath-equivalent-tests/Gen.hs#L38
There was a problem hiding this comment.
Do you think this generator would be worth publishing in a package we could use here?
That would be the preferred solution; copy-paste tends to multiply the maintenance effort.
If you consider this all feature-creep, you could also equip the property with a comment stating that this is the intended mathematical property but it is likely not established by the test because the coverage is very poor with the vanilla generator for FilePath = String.
There was a problem hiding this comment.
To not have this PR fizzle out, I merged it and pushed a disclaimer: 36a5fbf
My original intent was to add the disclaimer as an extra commit to this PR, but the PR wasn't set up in a way to allow contributions from the maintainers.
When passing a path like "F:/foo/bar" on windows
(both '/' and '\' are valid path separators on windows) we'll get garbage output like so:
...effectively turning an absolute path into a relative path ("F:foo\bar" on windows is the directory "foo\bar" relative to the current working directory on drive F).
This is because Posix and Windows splitDirectories behave differently:
When joining paths on windows, the filepath library does not assume a trailing path separator after the drive (here "F:"). This is because as described above, "F:foo" is a valid relative filepath.