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

Commit3967095

Browse files
authored
fix: validate url syntax before moving on to the next wizard step (#79)
1 parentf4710e2 commit3967095

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

‎src/main/kotlin/com/coder/toolbox/views/AuthWizardPage.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AuthWizardPage(
2020
) : CoderPage(context, context.i18n.ptrl("Authenticate toCoder")) {
2121
privateval shouldAutoLogin=MutableStateFlow(initialAutoLogin)
2222

23-
privateval signInStep=SignInStep(context)
23+
privateval signInStep=SignInStep(context,this::notify)
2424
privateval tokenStep=TokenStep(context)
2525
privateval connectStep=ConnectStep(context, shouldAutoLogin,this::notify,this::displaySteps, onConnect)
2626

‎src/main/kotlin/com/coder/toolbox/views/SignInStep.kt‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
packagecom.coder.toolbox.views
22

33
importcom.coder.toolbox.CoderToolboxContext
4+
importcom.coder.toolbox.util.toURL
45
importcom.coder.toolbox.views.state.AuthWizardState
56
importcom.jetbrains.toolbox.api.localization.LocalizableString
67
importcom.jetbrains.toolbox.api.ui.components.LabelField
@@ -9,14 +10,16 @@ import com.jetbrains.toolbox.api.ui.components.TextField
910
importcom.jetbrains.toolbox.api.ui.components.TextType
1011
importcom.jetbrains.toolbox.api.ui.components.ValidationErrorField
1112
importkotlinx.coroutines.flow.update
13+
importjava.net.MalformedURLException
1214

1315
/**
1416
* A page with a field for providing the Coder deployment URL.
1517
*
1618
* Populates with the provided URL, at which point the user can accept or
1719
* enter their own.
1820
*/
19-
classSignInStep(privatevalcontext:CoderToolboxContext) : WizardStep {
21+
classSignInStep(privatevalcontext:CoderToolboxContext, privatevalnotify: (String,Throwable)->Unit) :
22+
WizardStep {
2023
privateval urlField=TextField(context.i18n.ptrl("Deployment URL"),"",TextType.General)
2124
privateval descriptionField=LabelField(context.i18n.pnotr(""))
2225
privateval errorField=ValidationErrorField(context.i18n.pnotr(""))
@@ -53,12 +56,28 @@ class SignInStep(private val context: CoderToolboxContext) : WizardStep {
5356
}else {
5457
url
5558
}
56-
59+
try {
60+
validateRawUrl(url)
61+
}catch (e:MalformedURLException) {
62+
notify("URL is invalid", e)
63+
returnfalse
64+
}
5765
context.secrets.lastDeploymentURL= url
5866
AuthWizardState.goToNextStep()
5967
returntrue
6068
}
6169

70+
/**
71+
* Throws [MalformedURLException] if the given string violates RFC-2396
72+
*/
73+
privatefunvalidateRawUrl(url:String) {
74+
try {
75+
url.toURL()
76+
}catch (e:Exception) {
77+
throwMalformedURLException(e.message)
78+
}
79+
}
80+
6281
overridefunonBack() {
6382
// it's the first step. Can't go anywhere back from here
6483
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp