Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,19 @@ public static String locateOriginalText(String fullLicenseText, int startToken,
/**
* Check whether the given text contains only a single token
* <p>
* A single token string is a string that contains zero or one token,
* A single token string is a string that contains exactly one token,
* as identified by the {@link LicenseTextHelper#TOKEN_SPLIT_PATTERN}.
* Whitespace and punctuation such as dots, commas, question marks,
* and quotation marks are ignored.
* </p>
*
* @param text The text to test.
* @return {@code true} if the text contains zero or one token,
* @return {@code true} if the text contains exactly one token,
* {@code false} otherwise.
*/
public static boolean isSingleTokenString(@Nullable String text) {
if (text == null || text.isEmpty()) {
return true; // Zero tokens is considered a single token string
if (text == null || text.trim().isEmpty()) {
return false;
}
Matcher m = LicenseTextHelper.TOKEN_SPLIT_PATTERN.matcher(text);
boolean found = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,10 @@ public void testLicenseEqualsNoneLicense() throws InvalidSPDXAnalysisException,
}

public void testisSingleTokenString() {
assertTrue(LicenseCompareHelper.isSingleTokenString(null));
assertTrue(LicenseCompareHelper.isSingleTokenString(""));
assertTrue(LicenseCompareHelper.isSingleTokenString(" "));
assertTrue(LicenseCompareHelper.isSingleTokenString("\n"));
assertFalse(LicenseCompareHelper.isSingleTokenString(null));
assertFalse(LicenseCompareHelper.isSingleTokenString(""));
assertFalse(LicenseCompareHelper.isSingleTokenString(" "));
assertFalse(LicenseCompareHelper.isSingleTokenString("\n"));
assertTrue(LicenseCompareHelper.isSingleTokenString("'"));
assertTrue(LicenseCompareHelper.isSingleTokenString(" '"));
assertTrue(LicenseCompareHelper.isSingleTokenString("' "));
Expand Down