Skip to content

Commit

Permalink
JENKINS-20991 - Sanitize rev-parse output with trimToNull()
Browse files Browse the repository at this point in the history
  • Loading branch information
Evildethow authored and MarkEWaite committed Mar 6, 2016
1 parent 79b749a commit a9f57aa
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Expand Up @@ -676,10 +676,10 @@ public ObjectId revParse(String revName) throws GitException, InterruptedExcepti

String arg = sanitize(revName + "^{commit}");
String result = launchCommand("rev-parse", arg);
String line = firstLine(result);
String line = StringUtils.trimToNull(result);
if (line == null)
throw new GitException("rev-parse no content returned for " + revName);
return ObjectId.fromString(line.trim());
return ObjectId.fromString(line);
}

/**
Expand Down Expand Up @@ -729,10 +729,10 @@ private String sanitize(String arg) {
*/
public ObjectId validateRevision(String revName) throws GitException, InterruptedException {
String result = launchCommand("rev-parse", "--verify", revName);
String line = firstLine(result);
String line = StringUtils.trimToNull(result);
if (line == null)
throw new GitException("null first line from rev-parse(" + revName +")");
return ObjectId.fromString(line.trim());
throw new GitException("null result from rev-parse(" + revName +")");
return ObjectId.fromString(line);
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -1101,11 +1101,11 @@ public boolean isBareRepository(String GIT_DIR) throws GitException, Interrupted
String gitDir = "--git-dir=" + GIT_DIR;
ret = launchCommand(gitDir, "rev-parse", "--is-bare-repository");
}
String line = firstLine(ret);
String line = StringUtils.trimToNull(ret);
if (line == null)
throw new GitException("No output from bare repository check for " + GIT_DIR);

return !"false".equals(line.trim());
return !"false".equals(line);
}

public boolean isShallowRepository() {
Expand Down

0 comments on commit a9f57aa

Please sign in to comment.