fix: check if input domain is valid to avoid crash

This commit is contained in:
jk234ert 2021-02-25 17:29:04 +08:00
parent b67cb61fd8
commit 861a70993c
1 changed files with 1 additions and 1 deletions

View File

@ -112,7 +112,7 @@ class PickServerViewModel: NSObject {
return Just(Result.success(searchedServersFromAPI)).eraseToAnyPublisher()
}
// 2. No server found in the recorded list, check if searchText is a valid mastodon server domain
if let toSearchText = searchText, !toSearchText.isEmpty {
if let toSearchText = searchText, !toSearchText.isEmpty, let _ = URL(string: "https://\(toSearchText)") {
return self.context.apiService.instance(domain: toSearchText)
.map { return Result.success([Mastodon.Entity.Server(instance: $0.value)]) }
.catch({ error -> Just<Result<[Mastodon.Entity.Server], Error>> in