www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10348] New: isRooted is either wrong or poorly specified

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

           Summary: isRooted is either wrong or poorly specified
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-06-12
18:19:15 PDT ---
-----
import std.path;

void main()
{
    assert(!isAbsolute(r"\"));  // ok
    assert(!isRooted(r"\"));  // fails, path is rooted
}
-----

How can a non-absolute path be rooted? It doesn't make sense to me that r"\"
itself is rooted (where is it rooted? which drive or network drive?). It's not
a valid path on Windows.

Another example:

-----
import std.path;

void main()
{
    assert(!isAbsolute(r"\"));  // ok
    assert(absolutePath(r"\") != r"\");  // fails, it returned r"\"
}
-----

So if r"\" is not an absolute path, how can the absolute path of r"\" be r"\"
when it's not absolute?

The docs for isRooted state:

"Determines whether a path starts at a root directory."

So in that case absolutePath() should have no problem creating an absolute path
of such a rooted path. But you can't create an absolute path out of r"\". r"\"
is not rooted anywhere. I think isRooted should have these tests:

assert (!isRooted(`\`));  // changed
assert (!isRooted(`\foo`));  // changed
assert (isRooted(`d:\foo`));
assert (isRooted(`\\foo\bar`));
assert (!isRooted("foo"));
assert (!isRooted("d:foo"));

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 12 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10348



--- Comment #1 from Infiltrator <lt.infiltrator gmail.com> 2013-06-12 18:48:55
PDT ---
The fixes for this and #10347 are trivial once isRooted and isAbsolute are
properly defined.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10348


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |bugzilla kyllingen.net
         AssignedTo|nobody puremagic.com        |bugzilla kyllingen.net


--- Comment #2 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2013-07-28
08:59:24 PDT ---
Surely \ is a valid path on Windows.  Just open cmd.exe and run

    dir \

and it will list the files in the root directory of the current drive.

I agree that absoluteDir(`\`) returns a wrong result.  It should probably
return rootName(base) instead.  I'll take care of it.

Whether isRooted(`\`) should be true or false is just a matter of definition. 
`\` refers to the *root directory* of the current drive, so it made sense to me
to define it as true.  Redefining it now would be a breaking change.  If you
think it is worth it, it should at least be brought up for community discussion
first.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10348



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-07-28
13:24:17 PDT ---
(In reply to comment #2)
 I agree that absoluteDir(`\`) returns a wrong result.  It should probably
 return rootName(base) instead.  I'll take care of it.
.net seems to return the drive path, e.g.: ----- using System; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string path1 = "\\"; string fullPath; fullPath = Path.GetFullPath(path1); Console.WriteLine("GetFullPath('{0}') returns '{1}'", path1, fullPath); } } } ----- Prints: GetFullPath('\') returns 'c:\' So I guess only 'absolutePath' needs to be fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 28 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10348



--- Comment #4 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2013-07-31
10:42:18 PDT ---
Pull request 1442 coincidentally fixes this bug.

https://github.com/D-Programming-Language/phobos/pull/1442

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 31 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10348



--- Comment #5 from github-bugzilla puremagic.com 2013-08-06 14:38:59 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/23a1fe9ae0c31efce5acad379f59117063738c29
Added unittests for issue 10348

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 06 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10348


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 06 2013