From 7b692e55cde4634209942cca197acf392ca51558 Mon Sep 17 00:00:00 2001 From: usa Date: Fri, 18 Nov 2005 07:51:19 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 +++++ file.c | 9 +++++- test/ruby/test_path.rb | 71 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 098c4be764..e80533f2aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Nov 18 16:47:33 2005 NAKAMURA Usaku + + * 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:19:16 2005 Hirokazu Yamamoto * win32/win32.h (S_IFIFO): r,w = IO.pipe; r.stat.pipe? now diff --git a/file.c b/file.c index bdd12d0946..669929b606 100644 --- a/file.c +++ b/file.c @@ -2638,9 +2638,16 @@ rb_file_s_dirname(VALUE klass, VALUE 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..f7a45a3712 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_special # [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