diff options
author | Fabian Henneke <fabian@henneke.me> | 2020-05-14 10:06:36 +0200 |
---|---|---|
committer | Fabian Henneke <FabianHenneke@users.noreply.github.com> | 2020-05-14 12:00:30 +0200 |
commit | f806438f2c822fcf248e431d794aa1d1b65df3fa (patch) | |
tree | 1b3eb00812bd91e38cb5c37fdf839f09cf91fd82 | |
parent | 42981cd52ba6daa6b15af955bddd75abcc6be791 (diff) |
Use absolute paths for custom ports, relative for default port
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt index 3421e6a8..591a8581 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt @@ -95,24 +95,29 @@ abstract class BaseGitActivity : AppCompatActivity() { val previousUrl = url ?: "" // Whether we need the leading ssh:// depends on the use of a custom port. val hostnamePart = serverHostname.removePrefix("ssh://") - // We only support relative paths and trim everything scheme-specific. - val pathPart = serverPath.trimStart('/', ':') val newUrl = when (protocol) { Protocol.Ssh -> { val userPart = if (serverUser.isEmpty()) "" else "${serverUser.trimEnd('@')}@" val portPart = if (serverPort == "22" || serverPort.isEmpty()) "" else ":$serverPort" if (portPart.isEmpty()) { + // We only support relative paths with the standard port. + val pathPart = serverPath.trimStart('/', ':') "$userPart$hostnamePart:$pathPart" } else { + // We only support absolute paths with custom ports. + if (!serverPath.startsWith('/')) + return false + val pathPart = serverPath // We have to specify the ssh scheme as this is the only way to pass a custom // port. - "ssh://$userPart$hostnamePart$portPart/$pathPart" + "ssh://$userPart$hostnamePart$portPart$pathPart" } } Protocol.Https -> { val portPart = if (serverPort == "443" || serverPort.isEmpty()) "" else ":$serverPort" + val pathPart = serverPath.trimStart('/', ':') val urlWithFreeEntryScheme = "$hostnamePart$portPart/$pathPart" val url = when { urlWithFreeEntryScheme.startsWith("https://") -> urlWithFreeEntryScheme |