Skip to content

Commit 3c69eed

Browse files
committed
Fix LicenseRef validation to match the spec
Disallow LicenseRef-'s ending in '+' Also fixes some error documentation and JavaDocs Fixes #51 Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent cc35310 commit 3c69eed

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/main/java/org/spdx/library/model/v2/SpdxVerificationHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class SpdxVerificationHelper {
8686
SpdxConstantsCompatV2.CREATOR_PREFIX_ORGANIZATION, SpdxConstantsCompatV2.CREATOR_PREFIX_TOOL};
8787
static final String[] VALID_ORIGINATOR_SUPPLIER_PREFIXES = new String[] {SpdxConstantsCompatV2.NOASSERTION_VALUE, "Person:", "Organization:"};
8888
static final Pattern SPDX_ELEMENT_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$");
89-
static final Pattern LICENSE_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"([0-9a-zA-Z\\.\\-\\_]+)\\+?$");
89+
static final Pattern LICENSE_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"([0-9a-zA-Z\\.\\-\\_]+)$");
9090
static final Pattern EXTERNAL_DOC_REF_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$");;
9191
static final Pattern CREATED_DATE_PATTERN = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$");
9292

@@ -95,7 +95,7 @@ public static String verifyNonStdLicenseId(String licenseUri) {
9595
return null;
9696
} else {
9797
return "Invalid license objectUri '"+licenseUri+"'. Must start with 'LicenseRef-' " +
98-
"and made up of the characters from the set 'a'-'z', 'A'-'Z', '0'-'9', '+', '_', '.', and '-'.";
98+
"and made up of the characters from the set 'a'-'z', 'A'-'Z', '0'-'9', '.', and '-'.";
9999
}
100100
}
101101

src/main/java/org/spdx/library/model/v2/license/SimpleLicensingInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public abstract class SimpleLicensingInfo extends AnyLicenseInfo {
4040

4141
/**
4242
* Open or create a model object with the default store and default document URI
43-
* @param objectUri ID for this object - must be unique within the SPDX document
43+
* @param id ID for this object - must be unique within the SPDX document
4444
* @throws InvalidSPDXAnalysisException
4545
*/
4646
SimpleLicensingInfo(String id) throws InvalidSPDXAnalysisException {
@@ -54,7 +54,7 @@ public abstract class SimpleLicensingInfo extends AnyLicenseInfo {
5454
* Create a new SimpleLicensingInfo object
5555
* @param modelStore container which includes the license
5656
* @param documentUri URI for the SPDX document containing the license
57-
* @param objectUri identifier for the license
57+
* @param id identifier for the license
5858
* @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's
5959
* @param create if true, create the license if it does not exist
6060
* @throws InvalidSPDXAnalysisException

src/test/java/org/spdx/library/model/compat/v2/SpdxVerificationHelperTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ protected void tearDown() throws Exception {
5151
}
5252

5353
/**
54-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyNonStdLicenseid(java.lang.String)}.
54+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#verifyNonStdLicenseid(java.lang.String)}.
5555
*/
5656
public void testVerifyNonStdLicenseId() {
5757
assertTrue(Objects.isNull(SpdxVerificationHelper.verifyNonStdLicenseId(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"something")));
5858
assertFalse(Objects.isNull(SpdxVerificationHelper.verifyNonStdLicenseId("InvalidID")));
59+
assertFalse(Objects.isNull(SpdxVerificationHelper.verifyNonStdLicenseId(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"something+")));
5960
}
6061

6162
/**
62-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyCreator(java.lang.String)}.
63+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#verifyCreator(java.lang.String)}.
6364
*/
6465
public void testVerifyCreator() {
6566
assertTrue(Objects.isNull(SpdxVerificationHelper.verifyCreator("Person:me")));
@@ -69,7 +70,7 @@ public void testVerifyCreator() {
6970
}
7071

7172
/**
72-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyOriginator(java.lang.String)}.
73+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#verifyOriginator(java.lang.String)}.
7374
*/
7475
public void testVerifyOriginator() {
7576
assertTrue(Objects.isNull(SpdxVerificationHelper.verifyOriginator("Person:me")));
@@ -79,7 +80,7 @@ public void testVerifyOriginator() {
7980
}
8081

8182
/**
82-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#verifySupplier(java.lang.String)}.
83+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#verifySupplier(java.lang.String)}.
8384
*/
8485
public void testVerifySupplier() {
8586
assertTrue(Objects.isNull(SpdxVerificationHelper.verifySupplier("Person:me")));
@@ -89,7 +90,7 @@ public void testVerifySupplier() {
8990
}
9091

9192
/**
92-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyDate(java.lang.String)}.
93+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#verifyDate(java.lang.String)}.
9394
*/
9495
public void testVerifyDate() {
9596
DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT);
@@ -99,7 +100,7 @@ public void testVerifyDate() {
99100
}
100101

101102
/**
102-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyAnnotator(java.lang.String)}.
103+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#verifyAnnotator(java.lang.String)}.
103104
*/
104105
public void testVerifyAnnotator() {
105106
assertTrue(Objects.isNull(SpdxVerificationHelper.verifyAnnotator("Person:me")));
@@ -109,23 +110,23 @@ public void testVerifyAnnotator() {
109110
}
110111

111112
/**
112-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#isValidExternalDocRef(java.lang.String)}.
113+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#isValidExternalDocRef(java.lang.String)}.
113114
*/
114115
public void testIsValidExternalDocRef() {
115116
assertTrue(SpdxVerificationHelper.isValidExternalDocRef("DocumentRef-SPDXA"));
116117
assertFalse(SpdxVerificationHelper.isValidExternalDocRef("WrongDocRef-SPDXA"));
117118
}
118119

119120
/**
120-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#isValidUri(java.lang.String)}.
121+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#isValidUri(java.lang.String)}.
121122
*/
122123
public void testIsValidUri() {
123124
assertTrue(SpdxVerificationHelper.isValidUri("https://spdx.org/spdx-specification-21-web-version#h.h430e9ypa0j9"));
124125
assertFalse(SpdxVerificationHelper.isValidUri("bad uri"));
125126
}
126127

127128
/**
128-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyChecksumString(java.lang.String, org.spdx.library.model.compat.v2.compat.v2.enumerations.ChecksumAlgorithm)}.
129+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#verifyChecksumString(java.lang.String, org.spdx.library.model.v2.enumerations.ChecksumAlgorithm, java.lang.String)}.
129130
*/
130131
public void testVerifyChecksumString() {
131132
assertTrue(Objects.isNull(SpdxVerificationHelper.verifyChecksumString("bc527343c7ffc103111f3a694b004e2f", ChecksumAlgorithm.MD5, Version.CURRENT_SPDX_VERSION)));
@@ -153,7 +154,7 @@ public void testVerifyChecksumString() {
153154
}
154155

155156
/**
156-
* Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyDownloadLocation(java.lang.String)}.
157+
* Test method for {@link org.spdx.library.model.v2.SpdxVerificationHelper#verifyDownloadLocation(java.lang.String)}.
157158
*/
158159
public void testVerifyDownloadLocation() {
159160
assertTrue(Objects.isNull(SpdxVerificationHelper.verifyDownloadLocation("NONE")));

0 commit comments

Comments
 (0)