D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3937 - os.path.dirname fails on absolute path
Summary: os.path.dirname fails on absolute path
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: Shin Fujishiro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-12 12:45 UTC by Ellery Newcomer
Modified: 2015-06-09 01:27 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 Ellery Newcomer 2010-03-12 12:45:01 UTC
According to DDoc,

assert(dirname(dirname("/home/user")) == "");

however, that assert isn't in the unittest, and the actual result is ".".

I would prefer "/" to either result.

suggested fix:

--- path.d      (revision 1452)
+++ path.d      (working copy)
@@ -359,7 +359,7 @@
  * version(Posix)
  * {
  *     assert(dirname("/home/user") == "/home");
- *     assert(dirname(dirname("/home/user")) == "");
+ *     assert(dirname(dirname("/home/user")) == "/");
  * }
  * -----
  */
@@ -386,7 +386,7 @@
         version(Posix)
         {
             if (fullname[i - 1] == sep[0])
-            {   i--;
+            {   if(i > 1) i--;
                 break;
             }
         }
@@ -401,6 +401,7 @@
     version (Posix)
     {
         assert(dirname("/path/to/file") == "/path/to");
+        assert(dirname(dirname("/home/user")) == "/");
     }
     else
     {
Comment 1 Shin Fujishiro 2010-06-23 21:19:32 UTC
Fixed in svn r1692.  The fix will be included in release 2.048.