File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
main/kotlin/com/coder/gateway/util
test/kotlin/com/coder/gateway/util Expand file tree Collapse file tree 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 {
3131 if (path == " ~" || path == " \$ HOME" || path == " \$ {user.home}" ) {
3232 return System .getProperty(" user.home" )
3333 }
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(" ~/" ))) {
3538 return Path .of(System .getProperty(" user.home" ), path.substring(1 )).toString()
3639 }
37- if (path.startsWith(" \$ HOME" + File .separator)) {
40+ if (path.startsWith(" \$ HOME" + File .separator) || (os == OS . WINDOWS && path.startsWith( " \$ HOME/ " )) ) {
3841 return Path .of(System .getProperty(" user.home" ), path.substring(5 )).toString()
3942 }
40- if (path.startsWith(" \$ {user.home}" + File .separator)) {
43+ if (path.startsWith(" \$ {user.home}" + File .separator) || (os == OS . WINDOWS && path.startsWith( " \$ {user.home}/ " )) ) {
4144 return Path .of(System .getProperty(" user.home" ), path.substring(12 )).toString()
4245 }
4346 return path
Original file line number Diff line number Diff line change @@ -108,7 +108,14 @@ internal class PathExtensionsTest {
108108 // Do not replace if part of a larger string.
109109 assertEquals(home, expand(it))
110110 assertEquals(home, expand(it + File .separator))
111+ if (isWindows) {
112+ assertEquals(home, expand(it + " /" ))
113+ } else {
114+ assertEquals(it + " \\ " , expand(it + " \\ " ))
115+ }
111116 assertEquals(it + " hello" , expand(it + " hello" ))
117+ assertEquals(it + " hello/foo" , expand(it + " hello/foo" ))
118+ assertEquals(it + " hello\\ foo" , expand(it + " hello\\ foo" ))
112119 }
113120 }
114121}
You can’t perform that action at this time.
0 commit comments