Skip to content

Commit

Permalink
modified logic and error message in ValidBibtexKeyCheck.checkValue
Browse files Browse the repository at this point in the history
  • Loading branch information
diegos committed Jun 2, 2019
1 parent 9271562 commit bad8856
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ public ValidBibtexKeyChecker(boolean enforceLegalKey) {
public Optional<String> checkValue(String value) {

// Fix #2: BibtexKeyGenerator.cleanKey() does not accept a null value
// for the "value" parameter. The 'if' statement below is added to check for
// both a null and zero length string and to add the empty key warning.
if ((value == null) || (value.length() == 0)) {
return Optional.of(Localization.lang("BibTeX key is empty"));
// for the "value" parameter. The if statement below changes a null value
// to a blank string
String testValue;
if (value == null) {
testValue = "";
} else {
testValue = value;
}

String cleaned = BibtexKeyGenerator.cleanKey(value, enforceLegalKey);
String cleaned = BibtexKeyGenerator.cleanKey(testValue, enforceLegalKey);

if (cleaned.equals(value)) {
// Fix #3: added a test case that would take care of cases when the parameter
// "value" was either null or blank
if (testValue.length() == 0) {
return Optional.of(Localization.lang("empty BibTeX key"));
} else if (cleaned.equals(testValue)) {
return Optional.empty();
} else {
return Optional.of(Localization.lang("Invalid BibTeX key"));
Expand Down

0 comments on commit bad8856

Please sign in to comment.