File tree 2 files changed +13
-3
lines changed
main/kotlin/com/coder/gateway/util
test/kotlin/com/coder/gateway/util
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -31,13 +31,16 @@ fun expand(path: String): String {
31
31
if (path == " ~" || path == " \$ HOME" || path == " \$ {user.home}" ) {
32
32
return System .getProperty(" user.home" )
33
33
}
34
- if (path.startsWith(" ~" + File .separator)) {
34
+ // On Windows also allow /. Windows seems to work fine with mixed slashes
35
+ // like c:\users\coder/my/path/here.
36
+ val os = getOS()
37
+ if (path.startsWith(" ~" + File .separator) || (os == OS .WINDOWS && path.startsWith(" ~/" ))) {
35
38
return Path .of(System .getProperty(" user.home" ), path.substring(1 )).toString()
36
39
}
37
- if (path.startsWith(" \$ HOME" + File .separator)) {
40
+ if (path.startsWith(" \$ HOME" + File .separator) || (os == OS . WINDOWS && path.startsWith( " \$ HOME/ " )) ) {
38
41
return Path .of(System .getProperty(" user.home" ), path.substring(5 )).toString()
39
42
}
40
- if (path.startsWith(" \$ {user.home}" + File .separator)) {
43
+ if (path.startsWith(" \$ {user.home}" + File .separator) || (os == OS . WINDOWS && path.startsWith( " \$ {user.home}/ " )) ) {
41
44
return Path .of(System .getProperty(" user.home" ), path.substring(12 )).toString()
42
45
}
43
46
return path
Original file line number Diff line number Diff line change @@ -108,7 +108,14 @@ internal class PathExtensionsTest {
108
108
// Do not replace if part of a larger string.
109
109
assertEquals(home, expand(it))
110
110
assertEquals(home, expand(it + File .separator))
111
+ if (isWindows) {
112
+ assertEquals(home, expand(it + " /" ))
113
+ } else {
114
+ assertEquals(it + " \\ " , expand(it + " \\ " ))
115
+ }
111
116
assertEquals(it + " hello" , expand(it + " hello" ))
117
+ assertEquals(it + " hello/foo" , expand(it + " hello/foo" ))
118
+ assertEquals(it + " hello\\ foo" , expand(it + " hello\\ foo" ))
112
119
}
113
120
}
114
121
}
You can’t perform that action at this time.
0 commit comments