Bug 17490 – std.path.buildPath on Windows returns incorrect paths
Status
CLOSED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2017-06-11T13:29:00Z
Last change time
2017-06-11T20:14:39Z
Assigned to
nobody
Creator
dlang
Comments
Comment #0 by dlang — 2017-06-11T13:29:54Z
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 by dlang-bugzilla — 2017-06-11T13:41:56Z
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 by dlang — 2017-06-11T20:14:39Z
I didn't notice the normalizedPath variations. Thanks.