Skip to content

Commit 3da9fad

Browse files
author
Mark Robinson
committed
Relax validation requirements to allow directories
1 parent 1979c66 commit 3da9fad

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/main/java/org/commonwl/view/github/GitHubService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public class GitHubService {
5353
private final CommitService commitService;
5454

5555
// URL validation for directory links
56-
private final String GITHUB_CWL_REGEX = "^https?:\\/\\/github\\.com\\/([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)\\/?(?:tree|blob)\\/([^/]+)(?:\\/(.+\\.cwl))$";
57-
private final Pattern githubCwlPattern = Pattern.compile(GITHUB_CWL_REGEX);
56+
private final String GITHUB_URL_REGEX = "^https?:\\/\\/github\\.com\\/([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)\\/?(?:(?:tree|blob)\\/([^/]+)\\/?(.*)?)?$";
57+
private final Pattern githubUrlPattern = Pattern.compile(GITHUB_URL_REGEX);
5858

5959
@Autowired
6060
public GitHubService(@Value("${githubAPI.authentication}") String authSetting,
@@ -72,12 +72,12 @@ public GitHubService(@Value("${githubAPI.authentication}") String authSetting,
7272
}
7373

7474
/**
75-
* Extract the details of a Github cwl file URL using a regular expression
76-
* @param url The Github URL to a cwl file
75+
* Extract the details of a Github URL using a regular expression
76+
* @param url The Github URL to a directory or file
7777
* @return A list with the groups of the regex match, [owner, repo, branch, path]
7878
*/
79-
public GithubDetails detailsFromCwlURL(String url) {
80-
Matcher m = githubCwlPattern.matcher(url);
79+
public GithubDetails detailsFromURL(String url) {
80+
Matcher m = githubUrlPattern.matcher(url);
8181
if (m.find()) {
8282
return new GithubDetails(m.group(1), m.group(2), m.group(3), m.group(4));
8383
}

src/main/java/org/commonwl/view/workflow/WorkflowFormValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public GithubDetails validateAndParse(WorkflowForm form, Errors e) {
5858

5959
// Only continue if not null and isn't just whitespace
6060
if (!e.hasErrors()) {
61-
GithubDetails githubInfo = githubService.detailsFromCwlURL(form.getGithubURL());
61+
GithubDetails githubInfo = githubService.detailsFromURL(form.getGithubURL());
6262

6363
// If the URL is valid and details could be extracted
6464
if (githubInfo != null) {

0 commit comments

Comments
 (0)