Skip to content

Commit

Permalink
[FIXES JENKINS-15235]
Browse files Browse the repository at this point in the history
- 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 7a1e61e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/hudson/plugins/git/BranchSpec.java
Expand Up @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/hudson/plugins/git/TestBranchSpec.java
Expand Up @@ -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.