Bug 12114 – buildNormalizedPath shouldn't normalize current path to empty string
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-08T15:37:00Z
Last change time
2015-06-09T01:31:16Z
Assigned to
nobody
Creator
bus_dbugzilla
Comments
Comment #0 by bus_dbugzilla — 2014-02-08T15:37:03Z
Currently, buildNormalizedPath("."), buildNormalizedPath("foo/.."), etc all return empty string.
While buildNormalizedPath should indeed remove superfluous uses of "." within a path, paths that ultimately simplify to the current directory should result in "." not empty string (much like how buildNormalizedPath("..") returns "..").
This is for two reasons:
1. Other functions in std.path (rootName, driveName, extension) already use "" to mean "does not exist" which is very distinct from "current directory". When "current directory" is passed into buildNormalizedPath, the result should not be confusable with "does not exist".
2. To reduce the chances of accidental bugs like this:
auto from = buildNormalizedPath(...);
executeShell("cp "~from~ " target"); // Oops, the "from" argument might be missing!
Note that an empty input (such as buildNormalizedPath(), buildNormalizedPath(""), or buildNormalizedPath("", "")) should still result in an empty string (as it does now) so that "does not exist" cannot get accidentally converted to "current directory":
auto x = rootName("some/relative/path");
...
buildNormalizedPath(x); // Oops! A missing path got "normalized" to current directory.
Comment #1 by dlang-bugzilla — 2014-02-08T18:13:33Z
(In reply to comment #0)
> 2. To reduce the chances of accidental bugs like this:
> auto from = buildNormalizedPath(...);
> executeShell("cp "~from~ " target"); // Oops, the "from" argument might be
> missing!
For the record and as an aside, this is poor practice. escapeShellCommand should be used to build the command line, or (for this example) even better, execute instead of executeShell.
Comment #2 by cromfr — 2014-12-08T07:16:08Z
What should happen if you do buildNormalizedPath(".", "") ?
Comment #3 by github-bugzilla — 2014-12-14T06:18:00Z