Keep the trailing slash if the user wishes

bug/bundler_fix
sinn3r 2013-07-22 20:46:18 -05:00
parent 359009583f
commit 958a4edd73
2 changed files with 12 additions and 3 deletions

View File

@ -35,14 +35,14 @@ module FileUtils
# Filter out double slashes
s = s.gsub(/\\\\/, '\\') while s.index('\\\\')
# Keep the trailing slash if exists
trailing_s = ('\\' if s =~ /\\$/) || ''
# Check the items (fie/dir) individually
s = s.split(/\\/)
# Parse the path prefix
prefix = (s[0] || '').gsub(/[\*<>\?\/]/, '')
if prefix =~ /^\w:$/ and s.length == 1
prefix += '\\'
end
# Delete the original prefix. We want the new one later.
s.delete_at(0)
@ -55,6 +55,9 @@ module FileUtils
# And then safely join the items
s *= '\\'
# Add the trailing slash back if exists
s << trailing_s
end
#

View File

@ -17,6 +17,11 @@ describe Rex::FileUtils do
described_class.normalize_win_path('\\temp').should eq("\\temp")
end
it "should keep the trailing slash if exists" do
described_class.normalize_win_path('/', 'test', 'me\\').should eq("\\test\\me\\")
described_class.normalize_win_path('\\temp\\').should eq("\\temp\\")
end
it "should convert a path without reserved characters" do
described_class.normalize_win_path('C:\\', 'Windows:').should eq("C:\\Windows")
described_class.normalize_win_path('C:\\Windows???\\test').should eq("C:\\Windows\\test")
@ -26,6 +31,7 @@ describe Rex::FileUtils do
described_class.normalize_win_path('C:\\\\\\', 'Windows').should eq("C:\\Windows")
described_class.normalize_win_path('C:\\\\\\Hello World\\\\whatever.txt').should eq("C:\\Hello World\\whatever.txt")
described_class.normalize_win_path('C:\\\\').should eq("C:\\")
described_class.normalize_win_path('\\test\\\\test\\\\').should eq("\\test\\test\\")
end
end