Skip to content

Commit 3f443ee

Browse files
authored
Merge pull request #54 from spdx/issue53
Resolve issue #53 - fix regex for git download locations
2 parents 4210d72 + a60e100 commit 3f443ee

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/org/spdx/library/SpdxConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public class SpdxConstants {
361361
// Download Location Format
362362
private static final String SUPPORTED_DOWNLOAD_REPOS = "(git|hg|svn|bzr)";
363363
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})?(\\/.*)";
364-
private static final String GIT_PATTERN = "(git\\+git@[a-zA-Z0-9\\.]+:[a-zA-Z0-9]+)";
364+
private static final String GIT_PATTERN = "(git\\+git@[a-zA-Z0-9\\.]+:[a-zA-Z0-9/\\\\.@]+)";
365365
private static final String BAZAAR_PATTERN = "(bzr\\+lp:[a-zA-Z0-9\\.]+)";
366366
public static final Pattern DOWNLOAD_LOCATION_PATTERN = Pattern.compile("^(NONE|NOASSERTION|(("+SUPPORTED_DOWNLOAD_REPOS+"\\+)?"+URL_PATTERN+")|"+GIT_PATTERN+"|"+BAZAAR_PATTERN+")$", Pattern.CASE_INSENSITIVE);
367367

src/test/java/org/spdx/library/model/SpdxPackageTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,5 +1454,26 @@ public void testSetNameString() throws InvalidSPDXAnalysisException {
14541454
assertEquals(PKG_NAME2, pkg2.getName().get());
14551455
assertEquals(PKG_NAME2, pkg.getName().get());
14561456
}
1457+
1458+
public void testDownloadPattern() {
1459+
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1460+
"git://git.myproject.org/MyProject.git@master").matches());
1461+
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1462+
"git://git.myproject.org/MyOrg/MyProject.git@master").matches());
1463+
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1464+
"[email protected]:MyProject").matches());
1465+
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1466+
"[email protected]:MyOrg/MyProject").matches());
1467+
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1468+
"[email protected]:MyProject.git").matches());
1469+
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1470+
"[email protected]:MyOrg/MyProject.git").matches());
1471+
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1472+
"[email protected]:MyProject@main").matches());
1473+
assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1474+
"[email protected]:MyProject@6338c7a2525e055a05bae1580e4dd189c2feff7b").matches());
1475+
assertFalse(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(
1476+
"[email protected]:MyProject@6338c7a2525e055a05bae1580e4dd189c2feff7b").matches());
1477+
}
14571478

14581479
}

0 commit comments

Comments
 (0)