summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--file.c11
-rw-r--r--test/ruby/test_path.rb71
3 files changed, 88 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 3c61561953..13e3133987 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Nov 18 17:26:06 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * file.c (file_s_dirname): added checks for some patterns with drive
+ letter. fixed: [ruby-dev:27738]
+
+ * test/ruby/test_path.rb (test_dirname): added tests for above
+ patterns.
+
Fri Nov 18 12:18:02 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.h (S_IFIFO): r,w = IO.pipe; r.stat.pipe? now
diff --git a/file.c b/file.c
index 8db72a089a..36c5ed876e 100644
--- a/file.c
+++ b/file.c
@@ -2689,7 +2689,7 @@ rb_file_s_dirname(klass, fname)
root = skiproot(name);
#ifdef DOSISH_UNC
if (root > name + 1 && isdirsep(*name))
- root = skipprefix(name = root - 2);
+ name = root - 2;
#else
if (root > name + 1)
name = root - 1;
@@ -2700,9 +2700,16 @@ rb_file_s_dirname(klass, fname)
}
if (p == name)
return rb_str_new2(".");
+#ifdef DOSISH_DRIVE_LETTER
+ if (has_drive_letter(name) && isdirsep(*(name + 2))) {
+ dirname = rb_str_new(name, 3);
+ rb_str_cat(dirname, skiproot(name + 2), p - skiproot(name + 2));
+ }
+ else
+#endif
dirname = rb_str_new(name, p - name);
#ifdef DOSISH_DRIVE_LETTER
- if (root == name + 2 && name[1] == ':')
+ if (has_drive_letter(name) && root == name + 2 && p - name == 2)
rb_str_cat(dirname, ".", 1);
#endif
OBJ_INFECT(dirname, fname);
diff --git a/test/ruby/test_path.rb b/test/ruby/test_path.rb
index 95a5d5b1d1..4b9365508a 100644
--- a/test/ruby/test_path.rb
+++ b/test/ruby/test_path.rb
@@ -43,4 +43,75 @@ class TestPath < Test::Unit::TestCase
assert_equal("//", File.expand_path(".", "//"))
assert_equal("//sub", File.expand_path("sub", "//"))
end
+
+ def test_dirname # [ruby-dev:27738]
+ if /(bcc|ms)win\d|mingw|cygwin|djgpp|human|emx/ =~ RUBY_PLATFORM
+ # DOSISH_DRIVE_LETTER
+ assert_equal('C:.', File.dirname('C:'))
+ assert_equal('C:.', File.dirname('C:a'))
+ assert_equal('C:.', File.dirname('C:a/'))
+ assert_equal('C:a', File.dirname('C:a/b'))
+ assert_equal('C:/', File.dirname('C:/'))
+ assert_equal('C:/', File.dirname('C://'))
+ assert_equal('C:/', File.dirname('C:///'))
+ assert_equal('C:/', File.dirname('C:/a'))
+ assert_equal('C:/', File.dirname('C://a'))
+ assert_equal('C:/', File.dirname('C:///a'))
+ assert_equal('C:/', File.dirname('C:/a/'))
+ assert_equal('C:/', File.dirname('C://a/'))
+ assert_equal('C:/', File.dirname('C:///a/'))
+ assert_equal('C:/a', File.dirname('C:/a/b'))
+ assert_equal('C:/a', File.dirname('C://a/b'))
+ assert_equal('C:/a', File.dirname('C:///a/b'))
+ else
+ # others
+ assert_equal('.', File.dirname('C:'))
+ assert_equal('.', File.dirname('C:a'))
+ assert_equal('.', File.dirname('C:a/'))
+ assert_equal('C:a', File.dirname('C:a/b'))
+ assert_equal('.', File.dirname('C:/'))
+ assert_equal('.', File.dirname('C://'))
+ assert_equal('.', File.dirname('C:///'))
+ assert_equal('C:', File.dirname('C:/a'))
+ assert_equal('C:', File.dirname('C://a'))
+ assert_equal('C:', File.dirname('C:///a'))
+ assert_equal('C:', File.dirname('C:/a/'))
+ assert_equal('C:', File.dirname('C://a/'))
+ assert_equal('C:', File.dirname('C:///a/'))
+ assert_equal('C:/a', File.dirname('C:/a/b'))
+ # these show current implementation, but they are not spec.
+ #assert_equal('C://a', File.dirname('C://a/b'))
+ #assert_equal('C:///a', File.dirname('C:///a/b'))
+ end
+
+ assert_equal('.', File.dirname(''))
+ assert_equal('.', File.dirname('a'))
+ assert_equal('.', File.dirname('a/'))
+ assert_equal('a', File.dirname('a/b'))
+ assert_equal('/', File.dirname('/'))
+ assert_equal('/', File.dirname('/a'))
+ assert_equal('/', File.dirname('/a/'))
+ assert_equal('/a', File.dirname('/a/b'))
+ if /(bcc|ms|cyg)win|mingw|djgpp|human|emx/ =~ RUBY_PLATFORM
+ # DOSISH_UNC
+ assert_equal('//', File.dirname('//'))
+ assert_equal('//', File.dirname('//a'))
+ assert_equal('//', File.dirname('//a/'))
+ assert_equal('//a', File.dirname('//a/b'))
+ assert_equal('//', File.dirname('///'))
+ assert_equal('//', File.dirname('///a'))
+ assert_equal('//', File.dirname('///a/'))
+ assert_equal('//a', File.dirname('///a/b'))
+ else
+ # others
+ assert_equal('/', File.dirname('//'))
+ assert_equal('/', File.dirname('//a'))
+ assert_equal('/', File.dirname('//a/'))
+ assert_equal('/a', File.dirname('//a/b'))
+ assert_equal('/', File.dirname('///'))
+ assert_equal('/', File.dirname('///a'))
+ assert_equal('/', File.dirname('///a/'))
+ assert_equal('/a', File.dirname('///a/b'))
+ end
+ end
end