Skip to content

Commit f053201

Browse files
committed
Spdx2to3Converter: return null for "NONE" or "NOASSERTION" Agents
1 parent 2b3e699 commit f053201

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/java/org/spdx/library/conversion/Spdx2to3Converter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ public static Agent stringToAgent(String spdx2personOrgString, CreationInfo crea
346346
Objects.requireNonNull(idPrefix, "Creation info must have an idPrefix to accurately generate SPDX IDs");
347347
Matcher matcher = SPDX_2_CREATOR_PATTERN.matcher(spdx2personOrgString);
348348
if (!matcher.matches()) {
349+
// return null for NOASSERTION and NONE
350+
if ("NOASSERTION".equals(spdx2personOrgString) || "NONE".equals(spdx2personOrgString)) {
351+
return null;
352+
}
349353
// return a generic Agent
350354
Agent agent = (Agent)SpdxModelClassFactoryV3.getModelObject(creationInfo.getModelStore(),
351355
creationInfo.getIdPrefix() + creationInfo.getModelStore().getNextId(IdType.SpdxId),

src/test/java/org/spdx/library/conversion/Spdx2to3ConverterTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,5 +1951,29 @@ public void testConvertToLicenseExpression() throws InvalidSPDXAnalysisException
19511951
assertTrue(expected.isEmpty());
19521952
assertEquals(ands.toString(), result.getLicenseExpression());
19531953
}
1954+
1955+
@Test
1956+
public void testPackageSupplierNoAssertionAndNone() throws InvalidSPDXAnalysisException {
1957+
CreationInfo testCreationInfo = Spdx2to3Converter.convertCreationInfo(
1958+
new SpdxCreatorInformation(fromModelStore, DOCUMENT_URI,
1959+
fromModelStore.getNextId(IdType.Anonymous), copyManager, true)
1960+
.setCreated("2010-01-29T18:30:22Z"),
1961+
toModelStore, DEFAULT_PREFIX);
1962+
1963+
// "NOASSERTION" agent string
1964+
Agent resultNoAssertion = Spdx2to3Converter.stringToAgent("NOASSERTION", testCreationInfo);
1965+
assertNull("stringToAgent should return null for NOASSERTION value", resultNoAssertion);
1966+
1967+
// "NONE" agent string
1968+
Agent resultNone = Spdx2to3Converter.stringToAgent("NONE", testCreationInfo);
1969+
assertNull("stringToAgent should return null for NONE value", resultNone);
1970+
1971+
// Valid Person agent string
1972+
String personCreator = SpdxConstantsCompatV2.CREATOR_PREFIX_PERSON + "John Doe ([email protected])";
1973+
Agent resultPerson = Spdx2to3Converter.stringToAgent(personCreator, testCreationInfo);
1974+
assertNotNull("stringToAgent should return an Agent for valid Person format", resultPerson);
1975+
assertTrue("Result should be a Person", resultPerson instanceof Person);
1976+
assertEquals("John Doe", resultPerson.getName().get());
1977+
}
19541978

19551979
}

0 commit comments

Comments
 (0)