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 url syntax before moving on to the next wizard step#79

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
fioan89 merged 1 commit intomainfromvalidate-url
Apr 11, 2025
Merged
Show file tree
Hide file tree
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@ class AuthWizardPage(
) : CoderPage(context, context.i18n.ptrl("Authenticate to Coder")) {
private val shouldAutoLogin = MutableStateFlow(initialAutoLogin)

private val signInStep = SignInStep(context)
private val signInStep = SignInStep(context, this::notify)
private val tokenStep = TokenStep(context)
private val connectStep = ConnectStep(context, shouldAutoLogin, this::notify, this::displaySteps, onConnect)

Expand Down
23 changes: 21 additions & 2 deletionssrc/main/kotlin/com/coder/toolbox/views/SignInStep.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
package com.coder.toolbox.views

import com.coder.toolbox.CoderToolboxContext
import com.coder.toolbox.util.toURL
import com.coder.toolbox.views.state.AuthWizardState
import com.jetbrains.toolbox.api.localization.LocalizableString
import com.jetbrains.toolbox.api.ui.components.LabelField
Expand All@@ -9,14 +10,16 @@ import com.jetbrains.toolbox.api.ui.components.TextField
import com.jetbrains.toolbox.api.ui.components.TextType
import com.jetbrains.toolbox.api.ui.components.ValidationErrorField
import kotlinx.coroutines.flow.update
import java.net.MalformedURLException

/**
* A page with a field for providing the Coder deployment URL.
*
* Populates with the provided URL, at which point the user can accept or
* enter their own.
*/
class SignInStep(private val context: CoderToolboxContext) : WizardStep {
class SignInStep(private val context: CoderToolboxContext, private val notify: (String, Throwable) -> Unit) :
WizardStep {
private val urlField = TextField(context.i18n.ptrl("Deployment URL"), "", TextType.General)
private val descriptionField = LabelField(context.i18n.pnotr(""))
private val errorField = ValidationErrorField(context.i18n.pnotr(""))
Expand DownExpand Up@@ -53,12 +56,28 @@ class SignInStep(private val context: CoderToolboxContext) : WizardStep {
} else {
url
}

try {
validateRawUrl(url)
} catch (e: MalformedURLException) {
notify("URL is invalid", e)
return false
}
context.secrets.lastDeploymentURL = url
AuthWizardState.goToNextStep()
return true
}

/**
* Throws [MalformedURLException] if the given string violates RFC-2396
*/
private fun validateRawUrl(url: String) {
try {
url.toURL()
} catch (e: Exception) {
throw MalformedURLException(e.message)
}
}

override fun onBack() {
// it's the first step. Can't go anywhere back from here
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp