Skip to content

Commit

Permalink
Fix: Ignore superscript (^) and subscript (_) validation for citation…
Browse files Browse the repository at this point in the history
… key (JabRef#11948)
  • Loading branch information
Satyam Kumar Navneet authored and Satyam Kumar Navneet committed Jan 16, 2025
1 parent b701821 commit 55916ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;

import org.jabref.model.entry.field.InternalField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.ac.ed.ph.snuggletex.ErrorCode;
Expand Down Expand Up @@ -62,6 +63,8 @@ public class LatexIntegrityChecker implements EntryChecker {
@Override
public List<IntegrityMessage> check(BibEntry entry) {
return entry.getFieldMap().entrySet().stream()
// Ignore checks for the citation key field
.filter(field -> !(field.getKey().equals(InternalField.KEY_FIELD) && field.getValue().matches(".*[\\^_].*")))
.filter(field -> FieldFactory.isLatexField(field.getKey()))
.flatMap(LatexIntegrityChecker::getUnescapedAmpersandsWithCount)
// Exclude all DOM building errors as this functionality is not used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,18 @@ private static Stream<Arguments> provideUnacceptedInputs() {
Arguments.of(LatexIntegrityChecker.errorMessageFormatHelper(CoreErrorCode.TFEM03), StandardField.TITLE, "$\\right)$"),

// TFEM04: \left had no following \right
Arguments.of(LatexIntegrityChecker.errorMessageFormatHelper(CoreErrorCode.TFEM04), StandardField.TITLE, "$\\left($")
Arguments.of(LatexIntegrityChecker.errorMessageFormatHelper(CoreErrorCode.TFEM04), StandardField.TITLE, "$\\left($"),

// TFETB0: \hline must be the only token in table row
// Skipped

Arguments.of(LatexIntegrityChecker.errorMessageFormatHelper(CoreErrorCode.TTEM03), StandardField.TITLE, "Title with ^ and _ characters"),
// Ensure invalid LaTeX syntax with special characters in other fields is detected
Arguments.of(LatexIntegrityChecker.errorMessageFormatHelper(CoreErrorCode.TTEM03), StandardField.AUTHOR, "Author_Name"),
Arguments.of(LatexIntegrityChecker.errorMessageFormatHelper(CoreErrorCode.TTEM03), StandardField.JOURNAL, "Journal_Name"),
Arguments.of(LatexIntegrityChecker.errorMessageFormatHelper(CoreErrorCode.TTEM03), StandardField.BOOKTITLE, "Book^Title"),
Arguments.of(LatexIntegrityChecker.errorMessageFormatHelper(CoreErrorCode.TTEM03), StandardField.NOTE, "Note_with_subscript_and_superscript^_")

);
}
}

0 comments on commit 55916ca

Please sign in to comment.