Skip to content

Commit 734b754

Browse files
committed
fix: 不正なホスト名でログイン試行ができないように
これの影響でApp Review でクラッシュしてrejectされた
1 parent 5b99df2 commit 734b754

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Sources/iOS/App/Screens/Login/AddAccountIndexView.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ struct _AddAccountIndexView: View {
7070
@State var loginTask: Task<Void, Never>?
7171
@State var path: NavigationPath = .init()
7272
let errorReport: ((Error) -> Void)?
73+
var instanceValidateError: String? {
74+
if instance.isEmpty {
75+
return ""
76+
}
77+
if instance.contains("/") {
78+
return L10n.Login.ValidationFailed.hostIncludingSlash
79+
}
80+
var components = URLComponents()
81+
components.scheme = "https"
82+
components.host = instance
83+
if components.url == nil {
84+
return L10n.Login.ValidationFailed.hostIncludingSlash
85+
}
86+
return nil
87+
}
7388

7489
enum LoginState {
7590
case fetchingServerInfo
@@ -106,7 +121,7 @@ struct _AddAccountIndexView: View {
106121
} label: {
107122
Text(L10n.Login.loginButton)
108123
}
109-
.disabled(instance.count == 0 || loginState != nil)
124+
.disabled(instanceValidateError != nil || loginState != nil)
110125
.accessibility(identifier: "loginButton")
111126
#if DEBUG
112127
Button {
@@ -120,6 +135,8 @@ struct _AddAccountIndexView: View {
120135
} footer: {
121136
if let loginState = loginState {
122137
Text(loginState.description)
138+
} else if let instanceValidateError {
139+
Text(instanceValidateError)
123140
}
124141
}
125142
}

Sources/iOS/Core/Generated/strings_ios.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ public enum L10n {
289289
/// ログイン中
290290
public static let title = L10n.tr("Login", "progressDialog.title")
291291
}
292+
public enum ValidationFailed {
293+
/// ホスト名のみを入力してください (https:// や最後の / は含めないでください)
294+
public static let hostIncludingSlash = L10n.tr("Login", "validationFailed.hostIncludingSlash")
295+
}
292296
public enum Welcome {
293297
/// ようこそ、
294298
/// %@

Sources/iOS/Core/Strings/ja.lproj/Login.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
"title" = "ログイン";
1010
"pleaseInputMastodonInstance" = "Mastodonのインスタンスを入力してください";
11+
"validationFailed.hostIncludingSlash" = "ホスト名のみを入力してください (https:// や最後の / は含めないでください)";
1112
"loginButton" = "ログイン";
1213

1314
"progressDialog.title" = "ログイン中";

0 commit comments

Comments
 (0)