www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12114] New: buildNormalizedPath shouldn't normalize current path to empty string

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12114

           Summary: buildNormalizedPath shouldn't normalize current path
                    to empty string
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: cbkbbejeap mailinator.com


--- Comment #0 from Nick Sabalausky <cbkbbejeap mailinator.com> 2014-02-08
15:37:03 PST ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 08 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12114


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow gmail.com


--- Comment #1 from Vladimir Panteleev <thecybershadow gmail.com> 2014-02-09
04:13:33 EET ---
(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. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 08 2014