Permalink
Browse files

[FIXES JENKINS-15235]

- Trim branch name before storing it, since a valid branch name does
not begin or end with whitespace.
- Use same code for setting name in constructor and in setName().
Previously, there were no check for valid values in setName().
  • Loading branch information...
thesam committed Dec 19, 2012
1 parent 8c1d8b8 commit 7a1e61eb2f08b2ed4aebb31e3cee272cf8a54ee6
@@ -29,18 +29,18 @@ public String getName() {
return name;
}

public void setName(String value) {
this.name = value;
}

@DataBoundConstructor
public BranchSpec(String name) {
if(name == null)
public void setName(String name) {
if(name == null)
throw new IllegalArgumentException();
else if(name.length() == 0)
this.name = "**";
else
this.name = name;
this.name = name.trim();
}

@DataBoundConstructor
public BranchSpec(String name) {
setName(name);
}

public String toString() {
@@ -61,4 +61,11 @@ public void testNullName() {
assertTrue(correctExceptionThrown);
}

public void testNameTrimming() {
BranchSpec branchSpec = new BranchSpec(" master ");
assertEquals("master",branchSpec.getName());
branchSpec.setName(" other ");
assertEquals("other",branchSpec.getName());
}

}

0 comments on commit 7a1e61e

Please sign in to comment.