D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17490 - std.path.buildPath on Windows returns incorrect paths
Summary: std.path.buildPath on Windows returns incorrect paths
Status: CLOSED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All Windows
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-11 13:29 UTC by dlang
Modified: 2017-06-11 20:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description dlang 2017-06-11 13:29:54 UTC
std.path.buildPath should convert its input to the correct path representation (e.g., replace slashes with backslashes).

Most of the time, Windows can use the forward slash, but Phobos should always return paths with backslashes because:
- a couple of weird things can happen with some API functions [0].
- backslashes are required for extended-length paths (prepended with "\\?\") [1].
- consistency; if I'm going to print a path to the user, it needs to be what they'll expect, and I shouldn't have to modify what the standard library returns.

Note that Windows does call "\foo" an absolute path (it implicitly prepends the current drive).

> writeln(buildPath("c:\\asdf", "/bcd")); // "c:/bcd"; want "c:\bcd"
> writeln(buildPath("c:\\asdf/", "bcd")); // "c:\asdf/bcd"; want "c:\asdf\bcd"
> writeln(buildPath("c:/asdf", "d:/bcd")); // "d:/bcd"; want "d:\bcd"



[0] LoadLibrary: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx?f=255&MSPPError=-2147217396
"When specifying a path, be sure to use backslashes (\), not forward slashes (/)."

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#paths
Comment 1 Vladimir Panteleev 2017-06-11 13:41:56 UTC
Implicit conversions are evil and inefficient. If your program must not have forward slashes in its paths, then they should not have reached buildPath anyway. If you do want to normalize slashes, use buildNormalizedPath etc.
Comment 2 dlang 2017-06-11 20:14:39 UTC
I didn't notice the normalizedPath variations. Thanks.