Keep the trailing slash if the user wishes
parent
359009583f
commit
958a4edd73
|
@ -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
|
||||
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue