File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -35,14 +35,14 @@ def self.normalize_win_path(*strs)
35
35
# Filter out double slashes
36
36
s = s . gsub ( /\\ \\ / , '\\' ) while s . index ( '\\\\' )
37
37
38
+ # Keep the trailing slash if exists
39
+ trailing_s = ( '\\' if s =~ /\\ $/ ) || ''
40
+
38
41
# Check the items (fie/dir) individually
39
42
s = s . split ( /\\ / )
40
43
41
44
# Parse the path prefix
42
45
prefix = ( s [ 0 ] || '' ) . gsub ( /[\* <>\? \/ ]/ , '' )
43
- if prefix =~ /^\w :$/ and s . length == 1
44
- prefix += '\\'
45
- end
46
46
47
47
# Delete the original prefix. We want the new one later.
48
48
s . delete_at ( 0 )
@@ -55,6 +55,9 @@ def self.normalize_win_path(*strs)
55
55
56
56
# And then safely join the items
57
57
s *= '\\'
58
+
59
+ # Add the trailing slash back if exists
60
+ s << trailing_s
58
61
end
59
62
60
63
#
Original file line number Diff line number Diff line change 17
17
described_class . normalize_win_path ( '\\temp' ) . should eq ( "\\ temp" )
18
18
end
19
19
20
+ it "should keep the trailing slash if exists" do
21
+ described_class . normalize_win_path ( '/' , 'test' , 'me\\' ) . should eq ( "\\ test\\ me\\ " )
22
+ described_class . normalize_win_path ( '\\temp\\' ) . should eq ( "\\ temp\\ " )
23
+ end
24
+
20
25
it "should convert a path without reserved characters" do
21
26
described_class . normalize_win_path ( 'C:\\' , 'Windows:' ) . should eq ( "C:\\ Windows" )
22
27
described_class . normalize_win_path ( 'C:\\Windows???\\test' ) . should eq ( "C:\\ Windows\\ test" )
26
31
described_class . normalize_win_path ( 'C:\\\\\\' , 'Windows' ) . should eq ( "C:\\ Windows" )
27
32
described_class . normalize_win_path ( 'C:\\\\\\Hello World\\\\whatever.txt' ) . should eq ( "C:\\ Hello World\\ whatever.txt" )
28
33
described_class . normalize_win_path ( 'C:\\\\' ) . should eq ( "C:\\ " )
34
+ described_class . normalize_win_path ( '\\test\\\\test\\\\' ) . should eq ( "\\ test\\ test\\ " )
29
35
end
30
36
end
31
37
You can’t perform that action at this time.
0 commit comments