Skip to content

Commit

Permalink
Merge pull request #173 from spdx/notsogreedy
Browse files Browse the repository at this point in the history
Use non-greedy matches at start of textWith
  • Loading branch information
goneall committed May 9, 2023
2 parents a7fe5be + c7337a4 commit 46d5be3
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,15 @@ private static String findTemplateWithinText(String text, String template) throw
}

List<String> templateNonOptionalText = getNonOptionalLicenseText(removeCommentChars(template), VarTextHandling.REGEX);
if (templateNonOptionalText.size() > 0 && templateNonOptionalText.get(0).startsWith("~~~.")) {
// Change to a non-greedy match
String firstLine = templateNonOptionalText.get(0);
if (!firstLine.startsWith("~~~.?")) {
// yes - it's currently greedy
firstLine = "~~~.?" + firstLine.substring(4);
templateNonOptionalText.set(0, firstLine);
}
}
Pattern matchPattern = nonOptionalTextToStartPattern(templateNonOptionalText, CROSS_REF_NUM_WORDS_MATCH);
List<Pair<Integer, Integer>> charPositions = new ArrayList<>();
String normalizedText = removeCommentChars(normalizeText(text));
Expand Down

0 comments on commit 46d5be3

Please sign in to comment.