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

Official MIT license text is not recognized as MIT by LicenseCompareHelper.isStandardLicenseWithinText #241

Open
sdheh opened this issue Jun 4, 2024 · 4 comments · May be fixed by #249

Comments

@sdheh
Copy link

sdheh commented Jun 4, 2024

TLDR: LicenseCompareHelper.matchingStandardLicenseIdsWithinText does not match the MIT license text from https://spdx.org/licenses/MIT.html but LicenseCompareHelper.isTextStandardLicense does.
Version: 1.1.11 and allowing the fetching of recent license templates from the internet.

Details (steps to reproduce):
I copied the following text from https://spdx.org/licenses/MIT.html and used assigned it to the String licenseText:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

I ran the following code:

SpdxListedLicense mitLicense = ListedLicenses.getListedLicenses().getListedLicenseById("MIT");
System.out.println(LicenseCompareHelper.isTextStandardLicense(mitLicense, licenseText).isDifferenceFound());
System.out.println(LicenseCompareHelper.isStandardLicenseWithinText(licenseText, mitLicense));

This produces the following output:

false
false

but the output should be

false
true

The problem is in TemplateRegexMatcher.findTemplateWithinText, where the startPattern is

(?im)(\Qmit\E\s*\Qlicense\E\s*)?(.{0,5000})\Qpermission\E\s*\Qis\E\s*\Qhereby\E\s*\Qgranted\E\s*\Q,\E\s*\Qfree\E\s*\Qof\E\s*\Qcharge\E\s*\Q,\E\s*\Qto\E\s*\Qany\E\s*\Qperson\E\s*\Qobtaining\E\s*\Qa\E\s*\Qcopy\E\s*\Qof\E\s*(this\s+software\s+and\s+associated\s+documentation\s+files|this\s+source\s+file)\Q(\E\s*\Qthe\E\s*\Q'\E\s*\Qsoftware\E\s*\Q'\E\s*\Q)\E\s*\Q,\E\s*\Qto\E\s*\Qdeal\E\s*\Qin\E\s*

The problem is the following part:

file)\Q(\E

There is no \s* after file) so that is why this regex does not match the text.

@goneall
Copy link
Member

goneall commented Jun 4, 2024

Thanks @sdheh for the detailed analysis! This could explain some of the other issues.

It may be a little while before I can work on a fix myself since I'm heads-down working on the SPDX 3 upgrade. In the mean time pull requests would be welcome.

@pmonks
Copy link
Collaborator

pmonks commented Jun 4, 2024

I'm pretty sure this is a duplicate of #234.

@sdheh
Copy link
Author

sdheh commented Jun 5, 2024

By the way, the regex match will always include the first 5000 characters before the word "permission" because the beginning is optional and .{0,5000} is greedy. Is this intended?

@goneall
Copy link
Member

goneall commented Jun 15, 2024

By the way, the regex match will always include the first 5000 characters before the word "permission" because the beginning is optional and .{0,5000} is greedy. Is this intended?

It may be more efficient to make this match less greedy, but it shouldn't cause a problem since the follow-on calls to the token license matching algorithm will skip the "optional" text.

goneall added a commit that referenced this issue Sep 7, 2024
Fixes #241
Fixes #234

Include code provided by @pmonk in #236 modified for version 2.0+

Signed-off-by: Gary O'Neall <[email protected]>
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 a pull request may close this issue.

3 participants