Skip to content

Commit

Permalink
Checking for no value on secret
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Jul 31, 2023
1 parent 7bdd1f0 commit 0a6d739
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/UserControls/AddEditSecret.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@ public AddEditSecret(string secretName)
public string SecretName => txtName.Text.Trim();
public string SecretValue => txtSecret.Text.Trim();

private void Save_Click(object sender, RoutedEventArgs e)
private async void Save_Click(object sender, RoutedEventArgs e)
{
// Secret names can only contain alphanumeric characters ([a-z], [A-Z], [0-9]) or underscores (_). Spaces are not allowed. Must start with a letter ([a-z], [A-Z]) or underscores (_).
Regex rx = new Regex("^[a-zA-Z_][a-zA-Z0-9_]*$");
if (rx.IsMatch(txtName.Text))
{
DialogResult = true;
Close();
if (string.IsNullOrWhiteSpace(txtSecret.Text.Trim()))
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Community.VisualStudio.Toolkit.MessageBox mb = new();
mb.ShowError("Secret value cannot be empty.", "Invalid Secret Value");
}
else
{
DialogResult = true;
Close();
}
}
else
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Community.VisualStudio.Toolkit.MessageBox mb = new();
mb.ShowError("Secret names can only contain alphanumeric characters ([a-z], [A-Z], [0-9]) or underscores (_). Spaces are not allowed. Must start with a letter ([a-z], [A-Z]) or underscores (_).", "Invalid Secret Name");
}
Expand Down

0 comments on commit 0a6d739

Please sign in to comment.