Skip to content

Commit 9d18cf2

Browse files
committed
Merge pull request timols#115 from froque/sanitize-branches
sanitize branches before calling api.
2 parents 9cabcef + 1de9c6f commit 9d18cf2

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/main/java/org/gitlab/api/GitlabAPI.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,22 +1162,22 @@ public void createBranch(Serializable projectId, String branchName, String ref)
11621162
* @throws IOException on gitlab api call error
11631163
*/
11641164
public void deleteBranch(Serializable projectId, String branchName) throws IOException {
1165-
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBranch.URL + branchName;
1165+
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBranch.URL + sanitizeBranch(branchName);
11661166
retrieve().method("DELETE").to(tailUrl, Void.class);
11671167
}
11681168

11691169
public GitlabBranch getBranch(GitlabProject project, String branchName) throws IOException {
1170-
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + branchName;
1170+
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + sanitizeBranch(branchName);
11711171
return retrieve().to(tailUrl, GitlabBranch.class);
11721172
}
11731173

11741174
public void protectBranch(GitlabProject project, String branchName) throws IOException {
1175-
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + branchName + "/protect";
1175+
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + sanitizeBranch(branchName) + "/protect";
11761176
retrieve().method("PUT").to(tailUrl, Void.class);
11771177
}
11781178

11791179
public void unprotectBranch(GitlabProject project, String branchName) throws IOException {
1180-
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + branchName + "/unprotect";
1180+
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + sanitizeBranch(branchName) + "/unprotect";
11811181
retrieve().method("PUT").to(tailUrl, Void.class);
11821182
}
11831183

@@ -1735,6 +1735,14 @@ private String sanitizeProjectId(Serializable projectId) {
17351735
}
17361736
}
17371737

1738+
private String sanitizeBranch(String branch){
1739+
try {
1740+
return URLEncoder.encode(branch, "UTF-8");
1741+
} catch (UnsupportedEncodingException e) {
1742+
throw new RuntimeException((e));
1743+
}
1744+
}
1745+
17381746
/**
17391747
* Post comment to commit
17401748
*

0 commit comments

Comments
 (0)