Skip to content

Commit 06c2835

Browse files
committed
fix: url normalization
1 parent b57e9fa commit 06c2835

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

app/src/main/java/to/bitkit/ui/settings/advanced/RgsServerViewModel.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class RgsServerViewModel @Inject constructor(
9191
_uiState.update { it.copy(isLoading = true) }
9292

9393
viewModelScope.launch(bgDispatcher) {
94-
lightningRepo.restartWithRgsServer(url)
94+
lightningRepo.restartWithRgsServer(normalizeUrl(url))
9595
.onSuccess {
9696
_uiState.update {
9797
val newState = it.copy(
@@ -128,15 +128,12 @@ class RgsServerViewModel @Inject constructor(
128128
)
129129
}
130130

131-
private fun isValidURL(data: String): Boolean {
132-
val normalized = if (!data.startsWith("http://") && !data.startsWith("https://")) {
133-
"https://$data"
134-
} else {
135-
data
136-
}
131+
private fun normalizeUrl(url: String): String =
132+
if (!url.startsWith("http://") && !url.startsWith("https://")) "https://$url" else url
137133

134+
private fun isValidURL(data: String): Boolean {
138135
return runCatching {
139-
val uri = URI(normalized)
136+
val uri = URI(normalizeUrl(data))
140137
val hostname = uri.host ?: return false
141138

142139
if (Env.isDebug && hostname == "localhost") return true

0 commit comments

Comments
 (0)