• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

common-workflow-language / cwlviewer / #1994

12 May 2026 06:57PM UTC coverage: 70.713% (+0.4%) from 70.334%
#1994

Pull #751

github

kinow
Parse and validate Git URLs parsing URL, instead of using regexes (CodeQL security and performance warnings)
Pull Request #751: Bump org.springframework.boot:spring-boot-starter-parent from 3.1.4 to 4.1.0-RC1

93 of 148 new or added lines in 29 files covered. (62.84%)

19 existing lines in 3 files now uncovered.

1695 of 2397 relevant lines covered (70.71%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/src/main/java/org/commonwl/view/validation/AbstractGitValidator.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.commonwl.view.validation;
21

22
import java.net.URI;
23
import org.commonwl.view.git.GitDetails;
24
import org.commonwl.view.workflow.WorkflowForm;
25

26
/**
27
 * Abstract implementation of a Git validator.
28
 *
29
 * <p>Implementations must provide methods to retrieve the host and the base URL.
30
 */
31
public abstract class AbstractGitValidator implements GitUrlValidator {
1✔
32

33
  /**
34
   * Git host (e.g., github.com).
35
   *
36
   * @return Git host
37
   */
38
  protected abstract String host();
39

40
  /**
41
   * Git repository base URL (e.g., <a href="https://github.com/">...</a><owner>/<repo>.git).
42
   *
43
   * @param owner owner or organisation
44
   * @param repo repository name
45
   * @return a string representation of the Git repository base URL
46
   */
47
  protected abstract String repoBaseUrl(String owner, String repo);
48

49
  @Override
50
  public boolean supports(String url) {
51
    try {
52
      URI uri = URI.create(url);
1✔
53
      return host().equalsIgnoreCase(uri.getHost());
1✔
NEW
54
    } catch (Exception e) {
×
NEW
55
      return false;
×
56
    }
57
  }
58

59
  @Override
60
  public GitDetails parse(String url, WorkflowForm form) {
61
    final URI uri = URI.create(url);
1✔
62
    final String[] parts = uri.getPath().split("/");
1✔
63

64
    if (parts.length < 3) return null;
1✔
65

66
    final String owner = parts[1];
1✔
67
    final String repo = parts[2];
1✔
68

69
    final String repoUrl = repoBaseUrl(owner, repo);
1✔
70

71
    String branch = form.getBranch();
1✔
72
    String path = form.getPath();
1✔
73

74
    for (int i = 3; i < parts.length; i++) {
1✔
75
      if ("tree".equals(parts[i]) || "blob".equals(parts[i])) {
1✔
76
        if (branch == null && i + 1 < parts.length) {
1✔
77
          branch = parts[i + 1];
1✔
78
        }
79
        if (path == null && i + 2 < parts.length) {
1✔
80
          path = String.join("/", java.util.Arrays.copyOfRange(parts, i + 2, parts.length));
1✔
81
        }
82
        break;
83
      }
84
    }
85

86
    return new GitDetails(repoUrl, branch, path);
1✔
87
  }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc