Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: validate server URL has a host#57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 1 commit intomainfromethan/validate-url-host
Feb 18, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletionsCoder Desktop/Coder Desktop/Views/LoginForm.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,8 +63,11 @@ struct LoginForm<S: Session>: View {
guard sessionToken != "" else {
return
}
guard let url = URL(string: baseAccessURL), url.scheme == "https" else {
loginError = .invalidURL
let url: URL
do {
url = try validateURL(baseAccessURL)
} catch {
loginError = error
return
}
loading = true
Expand DownExpand Up@@ -152,8 +155,10 @@ struct LoginForm<S: Session>: View {
guard baseAccessURL != "" else {
return
}
guard let url = URL(string: baseAccessURL), url.scheme == "https" else {
loginError = .invalidURL
do {
try validateURL(baseAccessURL)
} catch {
loginError = error
return
}
withAnimation {
Expand All@@ -170,12 +175,32 @@ struct LoginForm<S: Session>: View {
}
}

enum LoginError {
@discardableResult
func validateURL(_ url: String) throws(LoginError) -> URL {
guard let url = URL(string: url) else {
throw LoginError.invalidURL
}
guard url.scheme == "https" else {
throw LoginError.httpsRequired
}
guard url.host != nil else {
throw LoginError.noHost
}
return url
}

enum LoginError: Error {
case httpsRequired
case noHost
case invalidURL
case failedAuth(ClientError)

var description: String {
switch self {
case .httpsRequired:
"URL must use HTTPS"
case .noHost:
"URL must have a host"
case .invalidURL:
"Invalid URL"
case let .failedAuth(err):
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp