summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-26 07:26:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-26 07:26:36 +0000
commit5212b7fb5206329151f52532e0818832186f0346 (patch)
tree1592961eaad50452efa2042a16d3ed8700161564
parent62bab7fc22ed4668fc2cca4b85965644046a1169 (diff)
file.c: fix for UNC
* file.c (realpath_rec): UNC prefix does not end with path separator, so new separator is needed after it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--file.c7
-rw-r--r--test/ruby/test_file.rb8
3 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 9b64ace4058..5af16c0cef2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat May 26 16:26:30 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (realpath_rec): UNC prefix does not end with path separator,
+ so new separator is needed after it.
+
Sat May 26 15:29:22 2012 Koichi Sasada <ko1@atdot.net>
* test/ruby/test_backtrace.rb (test_caller_lev):
diff --git a/file.c b/file.c
index bb1ab371f8a..846f3147f9f 100644
--- a/file.c
+++ b/file.c
@@ -3350,6 +3350,13 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE l
VALUE testpath = rb_str_dup(*resolvedp);
if (*prefixlenp < RSTRING_LEN(testpath))
rb_str_cat2(testpath, "/");
+#if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER)
+ if (*prefixlenp > 1 && *prefixlenp == RSTRING_LEN(testpath)) {
+ const char *prefix = RSTRING_PTR(testpath);
+ const char *last = rb_enc_left_char_head(prefix, prefix + *prefixlenp - 1, prefix + *prefixlenp, enc);
+ if (!isdirsep(*last)) rb_str_cat2(testpath, "/");
+ }
+#endif
rb_str_cat(testpath, testname, testnamelen);
checkval = rb_hash_aref(loopcheck, testpath);
if (!NIL_P(checkval)) {
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb
index b9c2210bdfe..b0a6971e69f 100644
--- a/test/ruby/test_file.rb
+++ b/test/ruby/test_file.rb
@@ -231,6 +231,14 @@ class TestFile < Test::Unit::TestCase
assert_equal(realdir, File.realdirpath(".", tst))
assert_equal(File.join(realdir, "foo"), File.realdirpath("foo", tst))
}
+ begin
+ result = File.realdirpath("bar", "//:/foo")
+ rescue SystemCallError
+ else
+ if result.start_with?("//")
+ assert_equal("//:/foo/bar", result)
+ end
+ end
end
def test_utime_with_minus_time_segv