ruby-changes:37537
From: nobu <ko1@a...>
Date: Tue, 17 Feb 2015 10:53:47 +0900 (JST)
Subject: [ruby-changes:37537] nobu:r49618 (trunk): win32/file.c: fix drive letter
nobu 2015-02-17 10:53:32 +0900 (Tue, 17 Feb 2015) New Revision: 49618 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49618 Log: win32/file.c: fix drive letter * win32/file.c (rb_file_expand_path_internal): do not make invalid (or ADS) path if the path has a drive letter, the result also should have be under it. [ruby-core:68130] [Bug #10858] Modified files: trunk/ChangeLog trunk/test/ruby/test_file_exhaustive.rb trunk/win32/file.c Index: ChangeLog =================================================================== --- ChangeLog (revision 49617) +++ ChangeLog (revision 49618) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Feb 17 10:53:29 2015 Nobuyoshi Nakada <nobu@r...> + + * win32/file.c (rb_file_expand_path_internal): do not make invalid + (or ADS) path if the path has a drive letter, the result also + should have be under it. [ruby-core:68130] [Bug #10858] + Tue Feb 17 10:47:20 2015 Iain Beeston <iain.beeston@g...> * hash.c: Added docs to explain that #include? and #member? do not Index: win32/file.c =================================================================== --- win32/file.c (revision 49617) +++ win32/file.c (revision 49618) @@ -401,6 +401,8 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L401 else { /* determine if we ignore dir or not later */ path_drive = wpath_pos[0]; + wpath_pos += 2; + wpath_len -= 2; } } else if (abs_mode == 0 && wpath_len >= 2 && wpath_pos[0] == L'~') { @@ -495,12 +497,7 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L497 /* determine if we ignore dir or not */ if (!ignore_dir && path_drive && dir_drive) { - if (towupper(path_drive) == towupper(dir_drive)) { - /* exclude path drive letter to use dir */ - wpath_pos += 2; - wpath_len -= 2; - } - else { + if (towupper(path_drive) != towupper(dir_drive)) { /* ignore dir since path drive is different from dir drive */ ignore_dir = 1; wdir_len = 0; @@ -534,6 +531,10 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L531 buffer_pos[0] = L'\\'; buffer_pos++; } + else if (!dir_drive && path_drive) { + *buffer_pos++ = path_drive; + *buffer_pos++ = L':'; + } if (wdir_len) { /* tainted if dir is used and dir is tainted */ Index: test/ruby/test_file_exhaustive.rb =================================================================== --- test/ruby/test_file_exhaustive.rb (revision 49617) +++ test/ruby/test_file_exhaustive.rb (revision 49618) @@ -795,6 +795,12 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L795 assert_equal("#{Dir.pwd}/a/b/c", File.expand_path(obj)) end + def test_expand_path_with_drive_letter + bug10858 = '[ruby-core:68130] [Bug #10858]' + assert_match(%r'/bar/foo\z'i, File.expand_path('z:foo', 'bar'), bug10858) + assert_equal('z:/bar/foo', File.expand_path('z:foo', '/bar'), bug10858) + end if DRIVE + def test_basename assert_equal(File.basename(@file).sub(/\.test$/, ""), File.basename(@file, ".test")) assert_equal("", s = File.basename("")) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/