1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2025-01-31 09:35:13 +01:00

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

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