From 333e8b294d4c7afb7a56cb4ea2b2c2820d5b17a6 Mon Sep 17 00:00:00 2001 From: usa Date: Tue, 22 Nov 2005 05:39:50 +0000 Subject: [PATCH] * file.c (rb_file_s_basename): skip slashes just after UNC top slashes. * test/ruby/test_path.rb (test_dirname, test_basename): follow new spec. and add new tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++ file.c | 4 +- test/ruby/test_path.rb | 129 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 124 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef1d5f4166..2622892cf7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Nov 22 14:36:54 2005 NAKAMURA Usaku + + * file.c (rb_file_s_basename): skip slashes just after UNC top slashes. + + * test/ruby/test_path.rb (test_dirname, test_basename): follow new + spec. and add new tests. + Tue Nov 22 13:30:15 2005 Hirokazu Yamamoto * win32/win32.c (rb_w32_stat): Dir.chdir('//server/shared'); diff --git a/file.c b/file.c index 57069cf3bb..873087c590 100644 --- a/file.c +++ b/file.c @@ -2225,7 +2225,9 @@ rb_path_skip_prefix(const char *path) #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER) #ifdef DOSISH_UNC if (isdirsep(path[0]) && isdirsep(path[1])) { - if (*(path = nextdirsep(path + 2)) && path[1] && !isdirsep(path[1])) + path += 2; + while (isdirsep(*path)) path++; + if (*(path = nextdirsep(path)) && path[1] && !isdirsep(path[1])) path = nextdirsep(path + 1); return (char *)path; } diff --git a/test/ruby/test_path.rb b/test/ruby/test_path.rb index 09ab4ac677..63dbd07346 100644 --- a/test/ruby/test_path.rb +++ b/test/ruby/test_path.rb @@ -51,17 +51,20 @@ class TestPath < Test::Unit::TestCase 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:/', 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:///a')) + assert_equal('C:/', File.dirname('C:///a/')) assert_equal('C:/a', File.dirname('C:///a/b')) else # others @@ -69,18 +72,22 @@ class TestPath < Test::Unit::TestCase 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('.', File.dirname('C://')) + assert_equal('C:', File.dirname('C://a')) + assert_equal('C:', File.dirname('C://a/')) + # not spec. #assert_equal('C://a', File.dirname('C://a/b')) + + assert_equal('.', File.dirname('C:///')) + assert_equal('C:', File.dirname('C:///a')) + assert_equal('C:', File.dirname('C:///a/')) + # not spec. #assert_equal('C:///a', File.dirname('C:///a/b')) end @@ -88,21 +95,24 @@ class TestPath < Test::Unit::TestCase 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('//a', File.dirname('//a')) - assert_equal('//a/', File.dirname('//a/')) + assert_equal('//a', File.dirname('//a/')) assert_equal('//a/b', File.dirname('//a/b')) assert_equal('//a/b', File.dirname('//a/b/')) assert_equal('//a/b', File.dirname('//a/b/c')) + assert_equal('//', File.dirname('///')) assert_equal('//a', File.dirname('///a')) - assert_equal('//a/', File.dirname('///a/')) + assert_equal('//a', File.dirname('///a/')) assert_equal('//a/b', File.dirname('///a/b')) assert_equal('//a/b', File.dirname('///a/b/')) assert_equal('//a/b', File.dirname('///a/b/c')) @@ -114,6 +124,7 @@ class TestPath < Test::Unit::TestCase assert_equal('/a', File.dirname('//a/b')) assert_equal('/a', File.dirname('//a/b/')) assert_equal('/a/b', File.dirname('//a/b/c')) + assert_equal('/', File.dirname('///')) assert_equal('/', File.dirname('///a')) assert_equal('/', File.dirname('///a/')) @@ -122,4 +133,92 @@ class TestPath < Test::Unit::TestCase assert_equal('/a/b', File.dirname('///a/b/c')) end end + + def test_basename # [ruby-dev:27766] + if /(bcc|ms)win\d|mingw|cygwin|djgpp|human|emx/ =~ RUBY_PLATFORM + # DOSISH_DRIVE_LETTER + assert_equal('', File.basename('C:')) + assert_equal('a', File.basename('C:a')) + assert_equal('a', File.basename('C:a/')) + assert_equal('b', File.basename('C:a/b')) + + assert_equal('/', File.basename('C:/')) + assert_equal('a', File.basename('C:/a')) + assert_equal('a', File.basename('C:/a/')) + assert_equal('b', File.basename('C:/a/b')) + + assert_equal('/', File.basename('C://')) + assert_equal('a', File.basename('C://a')) + assert_equal('a', File.basename('C://a/')) + assert_equal('b', File.basename('C://a/b')) + + assert_equal('/', File.basename('C:///')) + assert_equal('a', File.basename('C:///a')) + assert_equal('a', File.basename('C:///a/')) + assert_equal('b', File.basename('C:///a/b')) + else + # others + assert_equal('C:', File.basename('C:')) + assert_equal('C:a', File.basename('C:a')) + assert_equal('C:a', File.basename('C:a/')) + assert_equal('b', File.basename('C:a/b')) + + assert_equal('C:', File.basename('C:/')) + assert_equal('a', File.basename('C:/a')) + assert_equal('a', File.basename('C:/a/')) + assert_equal('b', File.basename('C:/a/b')) + + assert_equal('C:', File.basename('C://')) + assert_equal('a', File.basename('C://a')) + assert_equal('a', File.basename('C://a/')) + assert_equal('b', File.basename('C://a/b')) + + assert_equal('C:', File.basename('C:///')) + assert_equal('a', File.basename('C:///a')) + assert_equal('a', File.basename('C:///a/')) + assert_equal('b', File.basename('C:///a/b')) + end + + assert_equal('', File.basename('')) + assert_equal('a', File.basename('a')) + assert_equal('a', File.basename('a/')) + assert_equal('b', File.basename('a/b')) + + assert_equal('/', File.basename('/')) + assert_equal('a', File.basename('/a')) + assert_equal('a', File.basename('/a/')) + assert_equal('b', File.basename('/a/b')) + + if /(bcc|ms|cyg)win|mingw|djgpp|human|emx/ =~ RUBY_PLATFORM + # DOSISH_UNC + assert_equal('/', File.basename('//')) + assert_equal('/', File.basename('//a')) + assert_equal('/', File.basename('//a/')) + assert_equal('/', File.basename('//a/b')) + assert_equal('/', File.basename('//a/b/')) + assert_equal('c', File.basename('//a/b/c')) + + assert_equal('/', File.basename('///')) + assert_equal('/', File.basename('///a')) + assert_equal('/', File.basename('///a/')) + assert_equal('/', File.basename('///a/b')) + assert_equal('/', File.basename('///a/b/')) + assert_equal('c', File.basename('///a/b/c')) + else + # others + assert_equal('/', File.basename('//')) + assert_equal('a', File.basename('//a')) + assert_equal('a', File.basename('//a/')) + assert_equal('b', File.basename('//a/b')) + assert_equal('b', File.basename('//a/b/')) + assert_equal('c', File.basename('//a/b/c')) + + assert_equal('/', File.basename('///')) + assert_equal('a', File.basename('///a')) + assert_equal('a', File.basename('///a/')) + assert_equal('b', File.basename('///a/b')) + assert_equal('b', File.basename('///a/b/')) + assert_equal('c', File.basename('///a/b/c')) + end + end end