Skip to content

Commit

Permalink
Merge pull request #115 from thesam/jenkins15235
Browse files Browse the repository at this point in the history
[FIXES JENKINS-15235] Add whitespace trimming of branch name.
  • Loading branch information
ndeloof committed Dec 19, 2012
2 parents 707a991 + 7a1e61e commit 442eecd
Show file tree
Hide file tree
Showing 2 changed files with 31 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
23 changes: 23 additions & 0 deletions src/test/java/hudson/plugins/git/TestBranchSpec.java
Expand Up @@ -45,4 +45,27 @@ public void testMatch() {
Assert.assertTrue(p.matches("origin/x"));
Assert.assertFalse(p.matches("origin/my-branch/b1"));
}

public void testEmptyName() {
BranchSpec branchSpec = new BranchSpec("");
assertEquals("**",branchSpec.getName());
}

public void testNullName() {
boolean correctExceptionThrown = false;
try {
BranchSpec branchSpec = new BranchSpec(null);
} catch (IllegalArgumentException e) {
correctExceptionThrown = true;
}
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 442eecd

Please sign in to comment.