Skip to content

Commit c7337a4

Browse files
committed
Use non-greedy matches at start of textWith
Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent a7fe5be commit c7337a4

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,15 @@ private static String findTemplateWithinText(String text, String template) throw
945945
}
946946

947947
List<String> templateNonOptionalText = getNonOptionalLicenseText(removeCommentChars(template), VarTextHandling.REGEX);
948+
if (templateNonOptionalText.size() > 0 && templateNonOptionalText.get(0).startsWith("~~~.")) {
949+
// Change to a non-greedy match
950+
String firstLine = templateNonOptionalText.get(0);
951+
if (!firstLine.startsWith("~~~.?")) {
952+
// yes - it's currently greedy
953+
firstLine = "~~~.?" + firstLine.substring(4);
954+
templateNonOptionalText.set(0, firstLine);
955+
}
956+
}
948957
Pattern matchPattern = nonOptionalTextToStartPattern(templateNonOptionalText, CROSS_REF_NUM_WORDS_MATCH);
949958
List<Pair<Integer, Integer>> charPositions = new ArrayList<>();
950959
String normalizedText = removeCommentChars(normalizeText(text));

0 commit comments

Comments
 (0)