Skip to content

Commit

Permalink
Merge pull request #53 from pjdarton/enhance_jenkins_22437
Browse files Browse the repository at this point in the history
Enhance JENKINS-22437
  • Loading branch information
jswager committed Sep 16, 2016
2 parents ef95e6f + 8b7f8dd commit 8971edf
Showing 1 changed file with 15 additions and 0 deletions.
Expand Up @@ -3,9 +3,11 @@
import hudson.Extension;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

/**
* Represents a name/value pair that's sent to a vSphere virtual machine's
Expand All @@ -29,6 +31,7 @@ public String getValue() {
return value;
}

@SuppressWarnings("unchecked")
@Override
public Descriptor<VSphereGuestInfoProperty> getDescriptor() {
return Jenkins.getInstance().getDescriptor(getClass());
Expand All @@ -40,5 +43,17 @@ public static final class VSphereGuestInfoPropertyDescriptorImpl extends Descrip
public String getDisplayName() {
return null;
}

public FormValidation doCheckName(@QueryParameter String name) {
if (name == null || name.isEmpty()) {
return FormValidation.error("Must not be empty.");
}
final String acceptableCharacters = "a-zA-Z0-9_.-";
final String regex = "[" + acceptableCharacters + "]+";
if (!name.matches(regex)) {
return FormValidation.error("Unacceptable characters. Use only [" + acceptableCharacters + "].");
}
return FormValidation.ok();
}
}
}

0 comments on commit 8971edf

Please sign in to comment.