Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit e8e0cc7

Browse files
committed
Add check for potential issues with SSH URL
Signed-off-by: Harsh Shandilya <[email protected]>
1 parent 5d5a068 commit e8e0cc7

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
1111
- Add ability to view the Git commit log
1212
- Allow generating ECDSA and ED25519 keys for SSH
1313
- Add support for multiple/fallback authentication methods for SSH
14+
- Add warning when the custom SSH port in a URL could potentially be ignored
1415

1516
### Changed
1617

app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.zeapo.pwdstore.databinding.ActivityGitCloneBinding
2525
import com.zeapo.pwdstore.git.config.AuthMode
2626
import com.zeapo.pwdstore.git.config.GitSettings
2727
import com.zeapo.pwdstore.git.config.Protocol
28+
import com.zeapo.pwdstore.ui.dialogs.BasicBottomSheet
2829
import com.zeapo.pwdstore.utils.PasswordRepository
2930
import com.zeapo.pwdstore.utils.snackbar
3031
import com.zeapo.pwdstore.utils.viewBinding
@@ -87,6 +88,22 @@ class GitServerConfigActivity : BaseGitActivity() {
8788
}
8889

8990
binding.saveButton.setOnClickListener {
91+
val newUrl = binding.serverUrl.text.toString().trim()
92+
// If url is of type [email protected]:12435/path/to/repo, then not adding `ssh://`
93+
// in the beginning will cause the port to be seen as part of the path. Let users know
94+
// about it and offer a quickfix.
95+
if (newUrl.contains(":[0-9]{1,5}/".toRegex()) && !newUrl.startsWith("ssh://")) {
96+
BasicBottomSheet.Builder(this)
97+
.setTitleRes(R.string.ssh_scheme_needed_title)
98+
.setMessageRes(R.string.ssh_scheme_needed_message)
99+
.setPositiveButtonClickListener {
100+
@Suppress("SetTextI18n")
101+
binding.serverUrl.setText("ssh://$newUrl")
102+
}
103+
.build()
104+
.show(supportFragmentManager, "SSH_SCHEME_WARNING")
105+
return@setOnClickListener
106+
}
90107
when (val updateResult = GitSettings.updateConnectionSettingsIfValid(
91108
newAuthMode = newAuthMode,
92109
newUrl = binding.serverUrl.text.toString().trim(),

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,4 +436,8 @@
436436
<string name="err_enter_store_name">Enter a store name to continue</string>
437437
<string name="exception_cannot_create_directory">Cannot create new directory.</string>
438438

439+
<!-- SSH port validation -->
440+
<string name="ssh_scheme_needed_title">Potentially incorrect URL</string>
441+
<string name="ssh_scheme_needed_message">It appears that your URL contains a custom port, but does not specify the ssh:// scheme.\nThis can cause the port to be considered a part of your path. Press OK here to fix the URL.</string>
442+
439443
</resources>

0 commit comments

Comments
 (0)