Skip to content

Commit 3590095

Browse files
committed
Drop support for UNC path parsing in normalize_win_path
Not really a good idea to try to parse UNC format. Confuses the purpose of the function.
1 parent 8656fcf commit 3590095

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

lib/rex/file.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def self.normalize_win_path(*strs)
4040

4141
# Parse the path prefix
4242
prefix = (s[0] || '').gsub(/[\*<>\?\/]/, '')
43-
if prefix.empty?
44-
prefix = '\\'
45-
elsif prefix =~ /^\w:$/ and s.length == 1
43+
if prefix =~ /^\w:$/ and s.length == 1
4644
prefix += '\\'
4745
end
4846

spec/lib/rex/file_utils_spec.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
described_class.normalize_win_path('C:\\hello\\world').should eq("C:\\hello\\world")
1313
end
1414

15+
it "should convert a relative path" do
16+
described_class.normalize_win_path('/', 'test', 'me').should eq("\\test\\me")
17+
described_class.normalize_win_path('\\temp').should eq("\\temp")
18+
end
19+
1520
it "should convert a path without reserved characters" do
1621
described_class.normalize_win_path('C:\\', 'Windows:').should eq("C:\\Windows")
1722
described_class.normalize_win_path('C:\\Windows???\\test').should eq("C:\\Windows\\test")
@@ -22,16 +27,6 @@
2227
described_class.normalize_win_path('C:\\\\\\Hello World\\\\whatever.txt').should eq("C:\\Hello World\\whatever.txt")
2328
described_class.normalize_win_path('C:\\\\').should eq("C:\\")
2429
end
25-
26-
it "should parse UNC path format as an array or a string" do
27-
described_class.normalize_win_path('\\\\127.0.0.1', 'C$').should eq("\\\\127.0.0.1\\C$")
28-
described_class.normalize_win_path('\\\\127.0.0.1\\C$').should eq("\\\\127.0.0.1\\C$")
29-
end
30-
31-
it "should parse a relative path in Windows format" do
32-
described_class.normalize_win_path('\\\\127.0.0.1', 'C$').should eq("\\\\127.0.0.1\\C$")
33-
described_class.normalize_win_path('\\\\127.0.0.1\\C$').should eq("\\\\127.0.0.1\\C$")
34-
end
3530
end
3631

3732
context ".normalize_unix_path" do

0 commit comments

Comments
 (0)