Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/library/SpdxConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public class SpdxConstants {
// Download Location Format
private static final String SUPPORTED_DOWNLOAD_REPOS = "(git|hg|svn|bzr)";
private static final String URL_PATTERN = "(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/|ssh:\\/\\/|git:\\/\\/|svn:\\/\\/|sftp:\\/\\/|ftp:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+){0,100}\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)";
private static final String GIT_PATTERN = "(git\\+git@[a-zA-Z0-9\\.]+:[a-zA-Z0-9]+)";
private static final String GIT_PATTERN = "(git\\+git@[a-zA-Z0-9\\.]+:[a-zA-Z0-9/\\\\.@]+)";
private static final String BAZAAR_PATTERN = "(bzr\\+lp:[a-zA-Z0-9\\.]+)";
public static final Pattern DOWNLOAD_LOCATION_PATTERN = Pattern.compile("^(NONE|NOASSERTION|(("+SUPPORTED_DOWNLOAD_REPOS+"\\+)?"+URL_PATTERN+")|"+GIT_PATTERN+"|"+BAZAAR_PATTERN+")$", Pattern.CASE_INSENSITIVE);

Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/spdx/library/model/SpdxPackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1454,5 +1454,26 @@ public void testSetNameString() throws InvalidSPDXAnalysisException {
assertEquals(PKG_NAME2, pkg2.getName().get());
assertEquals(PKG_NAME2, pkg.getName().get());
}

public void testDownloadPattern() {
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"git://git.myproject.org/MyProject.git@master").matches());
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"git://git.myproject.org/MyOrg/MyProject.git@master").matches());
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"git+git@git.myproject.org:MyProject").matches());
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"git+git@git.myproject.org:MyOrg/MyProject").matches());
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"git+git@git.myproject.org:MyProject.git").matches());
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"git+git@git.myproject.org:MyOrg/MyProject.git").matches());
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"git+git@git.myproject.org:MyProject@main").matches());
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"git+git@git.myproject.org:MyProject@6338c7a2525e055a05bae1580e4dd189c2feff7b").matches());
assertFalse(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
"something@git.myproject.org:MyProject@6338c7a2525e055a05bae1580e4dd189c2feff7b").matches());
}

}