Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reinstating validation of CVS Root field and fixing JENKINS-9670
  • Loading branch information
mc1arke committed Jan 2, 2012
1 parent cec3235 commit d7531fa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/hudson/scm/CVSSCM.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.scm;

import static hudson.Util.fixEmpty;
import static hudson.Util.fixEmptyAndTrim;
import static hudson.Util.fixNull;
import hudson.Extension;
Expand Down Expand Up @@ -61,6 +62,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

Expand Down Expand Up @@ -896,6 +898,9 @@ private class RepositoryBrowser {
@SuppressWarnings("unused")
private transient Map<String, RepositoryBrowser> browsers;
// end legacy fields

private static final Pattern CVSROOT_PSERVER_PATTERN =
Pattern.compile(":(ext|extssh|pserver):[^@^:]+(:[^@]*)?@[^:]+:(\\d+:)?.+");

/**
* CVS compression level if individual repositories don't specifically
Expand Down Expand Up @@ -1050,7 +1055,29 @@ public FormValidation doCheckPattern(@QueryParameter final String value) {
}
return FormValidation.ok();
}

public FormValidation doCheckCvsRoot(@QueryParameter String value) throws IOException {
String v = fixEmpty(value);
if(v==null) {
return FormValidation.error(Messages.CVSSCM_MissingCvsroot());
}

Matcher m = CVSROOT_PSERVER_PATTERN.matcher(v);

// CVSROOT format isn't really that well defined. So it's hard to check this rigorously.
if(v.startsWith(":pserver") || v.startsWith(":ext")) {
if(!m.matches()) {
return FormValidation.error(Messages.CVSSCM_InvalidCvsroot());
}
// I can't really test if the machine name exists, either.
// some cvs, such as SOCKS-enabled cvs can resolve host names that Jenkins might not
// be able to. If :ext is used, all bets are off anyway.
}


return FormValidation.ok();
}

}

/**
Expand Down

0 comments on commit d7531fa

Please sign in to comment.