Skip to content

Commit f358b50

Browse files
authored
chore: Add null check to the Bitbucket Server URL parser (#983)
1 parent f4eb22d commit f358b50

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParser.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,17 @@ private BitbucketServerUrl parse(Matcher matcher, @Nullable String revision) {
304304
project = matcher.group("project");
305305
}
306306
String repoName = matcher.group("repo");
307-
String branchFromUrl = null;
307+
String branch = null;
308308
try {
309-
String branch = matcher.group("branch");
310-
branchFromUrl =
311-
branch.startsWith("refs/heads/")
312-
? branch.substring(11)
313-
: (branch.startsWith("refs%2Fheads%2F") ? branch.substring(15) : branch);
309+
String branchFromUrl = matcher.group("branch");
310+
if (!isNullOrEmpty(branchFromUrl)) {
311+
branch =
312+
branchFromUrl.startsWith("refs/heads/")
313+
? branchFromUrl.substring(11)
314+
: (branchFromUrl.startsWith("refs%2Fheads%2F")
315+
? branchFromUrl.substring(15)
316+
: branchFromUrl);
317+
}
314318
} catch (IllegalArgumentException e) {
315319
// keep branch with null, as the pattern doesn't have the branch group
316320
}
@@ -322,7 +326,7 @@ private BitbucketServerUrl parse(Matcher matcher, @Nullable String revision) {
322326
.withProject(project)
323327
.withUser(user)
324328
.withRepository(repoName)
325-
.withBranch(isNullOrEmpty(branchFromUrl) ? revision : branchFromUrl)
329+
.withBranch(isNullOrEmpty(branch) ? revision : branch)
326330
.withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames());
327331
}
328332
}

wsmaster/che-core-api-factory-bitbucket-server/src/test/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParserTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ public Object[][] expectedParsing() {
471471
"repo",
472472
"branch"
473473
},
474+
{"https://bitbucket.2mcl.com/users/user/repos/repo/browse", "user", null, "repo", null},
474475
{"https://bbkt.com/users/user/repos/repo/", "user", null, "repo", null}
475476
};
476477
}

0 commit comments

Comments
 (0)