Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow CycloneDX 1.5 spec for SPDX license expressions #975

Merged
merged 9 commits into from
Apr 13, 2024

Conversation

validide
Copy link
Contributor

Somewhat duplicate of pull request #690.

Closes #679.

@prabhu, I am not sure if you want the implementation to check all of those cases also considering there is a list of known licenses. If you think something is wrong let me know.

@prabhu
Copy link
Collaborator

prabhu commented Apr 13, 2024

@validide can you look into this line and see if we can create a new utils method and reuse this logic?

https://github.com/CycloneDX/cdxgen/blob/master/binary.js#L577

I have created the below to fix the test failure in blint.

owasp-dep-scan/blint#86

utils.js Outdated
}

if (
spdxLicenseExpressionOp.some((op) => {
Copy link
Collaborator

@prabhu prabhu Apr 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be simplified to check for the characters space and open bracket ( using regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it check for the existence of both characters or at least one? I have see license expressions without the ( character.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I meant either.

@validide
Copy link
Contributor Author

@validide can you look into this line and see if we can create a new utils method and reuse this logic?

https://github.com/CycloneDX/cdxgen/blob/master/binary.js#L577

I have created the below to fix the test failure in blint.

owasp-dep-scan/blint#86

I will check but which logic should be preserved the one from here or the one I created?

@prabhu
Copy link
Collaborator

prabhu commented Apr 13, 2024

@validide your logic is good but shall we try with a regex instead of a for-loop?

Signed-off-by: Valentin Dide <[email protected]>
Signed-off-by: Valentin Dide <[email protected]>
Signed-off-by: Valentin Dide <[email protected]>
Signed-off-by: Valentin Dide <[email protected]>
utils.js Outdated
return true;
}

if (licenseLoweCase.endsWith("+")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the "GPL-2.0+" (or latter) scenario. If this would be part of a more complex case it would be covered by the check for (space) or (.

utils.js Outdated
* @see https://spdx.dev/learn/handling-license-info/
**/
export function isSpdxLicenseExpression(license) {
const licenseLoweCase = (license || "").toLowerCase();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this variable to licenseLowerCase or reuse the same license variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change it.

utils.js Outdated
**/
export function isSpdxLicenseExpression(license) {
const licenseLoweCase = (license || "").toLowerCase();
if (!licenseLoweCase) {
Copy link
Collaborator

@prabhu prabhu Apr 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition will always be false since we substitute empty value above.

Copy link
Contributor Author

@validide validide Apr 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the function receives an undefined/null value we will have an empty string here. The empty string is "falsy". I was thinking it's not worth it to do all the logic on an empty string.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah. For some reason, I forgot this falsy thing and assumed only python behaves this way. Another learning for today!

utils.js Outdated
return false;
}

if (/[(\s]+/gi.test(licenseLoweCase)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/g instead of /gi since case insensitivity will not make a difference when looking for space and bracket character.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change it.

*
* @returns {string} ISO formatted timestamp, without milliseconds.
*/
export function getTimestamp() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

* @returns {string} ISO formatted timestamp, without milliseconds.
*/
export function getTimestamp() {
return new Date().toISOString().split(".")[0] + "Z";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, I think jsonschema date-time is wrong to leave out millseconds and move away from ISO8601 format.

Copy link
Collaborator

@prabhu prabhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much!

Signed-off-by: Valentin Dide <[email protected]>
@validide
Copy link
Contributor Author

Thank you so much!

You're welcomed!

I saw there were other discussions about moving to TypeScript and I believe that would be a huge amount of work. Since you are more familiar with the project would using JSDoc or cyclonedx-javascript-library be simpler? I think this is a nice project but I am more scared to do a change now than 24h ago.

@prabhu
Copy link
Collaborator

prabhu commented Apr 13, 2024

@validide, I agree. Using jsdoc is the safest option. Perhaps this issue to upgrade to eslint v9 or move to biomejs might give us good value. Would you like to take it up?

@validide
Copy link
Contributor Author

validide commented Apr 13, 2024

As much as I would like to, I have very limited time at the moment.

@prabhu prabhu merged commit a6e7947 into CycloneDX:master Apr 13, 2024
15 checks passed
@prabhu
Copy link
Collaborator

prabhu commented Apr 14, 2024

@validide, any thoughts on how we can simplify this project to attract more contributors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cdxgen does not follow CycloneDX 1.4 spec for SPDX license expressions
2 participants