Skip to content

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

@sdheh

Description

@sdheh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    matchingLicense matching and recognition

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions