Skip to content

Commit d270847

Browse files
authored
Move license matching code which removes underlines (#160)
Fixes an issue with matching caused by PR #156 Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent cffcbf9 commit d270847

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ public static String removeCommentChars(String s) {
230230
line = line.replaceAll("(\\*/|-->|-\\}|\\*\\))\\s*$", ""); // remove end of line comments
231231
line = line.replaceAll("^\\s*" + START_COMMENT_CHAR_PATTERN, ""); // remove start of line comments
232232
line = line.replaceAll("^\\s*<<beginOptional>>\\s*" + START_COMMENT_CHAR_PATTERN, "<<beginOptional>>");
233-
line = line.replaceAll("(-|=|\\*){3,}", ""); // Remove ----, ***, and ====
234233
sb.append(line);
235234
sb.append("\n");
236235
line = reader.readLine();
@@ -940,6 +939,7 @@ private static String findTemplateWithinText(String text, String template) throw
940939
Pattern matchPattern = nonOptionalTextToStartPattern(templateNonOptionalText, CROSS_REF_NUM_WORDS_MATCH);
941940
List<Pair<Integer, Integer>> charPositions = new ArrayList<>();
942941
String normalizedText = removeCommentChars(normalizeText(text));
942+
normalizedText = normalizedText.replaceAll("(-|=|\\*){3,}", ""); // Remove ----, ***, and ====
943943
String compareText;
944944
try {
945945
compareText = normalizeTokensForRegex(normalizedText, charPositions);

src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ public void testIsStandardLicenseWithinText() throws InvalidSPDXAnalysisExceptio
718718
SpdxListedLicense gpl30 = ListedLicenses.getListedLicenses().getListedLicenseById("GPL-3.0");
719719
SpdxListedLicense apache10 = ListedLicenses.getListedLicenses().getListedLicenseById("Apache-1.0");
720720
SpdxListedLicense apache20 = ListedLicenses.getListedLicenses().getListedLicenseById("Apache-2.0");
721+
SpdxListedLicense mplLicense = ListedLicenses.getListedLicenses().getListedLicenseById("MPL-2.0");
721722
String multiLicenseText = gpl30.getLicenseText() + "\n\n----------\n\n" + apache20.getLicenseText();
722723
String textWithRandomPrefixAndSuffix = "Some random preamble text.\n\n" + apache20.getLicenseText() + "\n\nSome random epilogue text.";
723724

@@ -730,8 +731,9 @@ public void testIsStandardLicenseWithinText() throws InvalidSPDXAnalysisExceptio
730731
assertTrue(LicenseCompareHelper.isStandardLicenseWithinText(textWithRandomPrefixAndSuffix, apache20));
731732
assertFalse(LicenseCompareHelper.isStandardLicenseWithinText(multiLicenseText, apache10));
732733
String mplText = UnitTestHelper.fileToText(MPL_2_FROM_MOZILLA_FILE);
733-
assertTrue(LicenseCompareHelper.isStandardLicenseWithinText(mplText, ListedLicenses.getListedLicenses().getListedLicenseById("MPL-2.0")));
734-
734+
assertTrue(LicenseCompareHelper.isStandardLicenseWithinText(mplText, mplLicense));
735+
DifferenceDescription mplDiff = LicenseCompareHelper.isTextStandardLicense(mplLicense, mplText);
736+
assertFalse(mplDiff.isDifferenceFound());
735737

736738
/* Currently doesn't work - see https://github.com/spdx/Spdx-Java-Library/issues/141 for details
737739
// JavaMail license is "CDDL-1.1 OR GPL-2.0 WITH Classpath-exception-2.0"

0 commit comments

Comments
 (0)