Skip to content

Bug: MonthChecker Uses Partial Regex Match — Invalid Month Values Pass Validation #15577

@Manishnemade12

Description

@Manishnemade12

JabRef version

5.15 (latest release)

Operating system

GNU / Linux

Details on version and operating system

No response

Checked with the latest development build (copy version output from About dialog)

  • I made a backup of my libraries before testing the latest development version.
  • I have tested the latest development version and the problem persists

Steps to reproduce the behaviour

  1. Edit a BibTeX entry and set the month field to an invalid mixed-string value like "1abc" or "#jan# foobar".
  2. Run JabRef's integrity check.
  3. Observe that no warning is generated for these invalid values.

Technical Root Cause:
MonthChecker uses Pattern.compile(...).asPredicate() for both ONLY_AN_INTEGER and MONTH_NORMALIZED. The asPredicate() method in Java uses Matcher.find() internally, meaning it performs a substring / partial match, not a full-string match.

  • "#jan# foobar" passes MONTH_NORMALIZED because #jan# is found as a substring.
  • "1abc" passes ONLY_AN_INTEGER because "1" is found.

Appendix

Proposed Fix:
In jablib/src/main/java/org/jabref/logic/integrity/MonthChecker.java:
Switch from asPredicate() to asMatchPredicate() (which uses Matcher.matches()) and add boundary anchors to enforce full-string matching:

- private static final Predicate<String> ONLY_AN_INTEGER = Pattern.compile("[1-9]|10|11|12")
-                                                                  .asPredicate();
- private static final Predicate<String> MONTH_NORMALIZED = Pattern
-         .compile("#jan#|#feb#|#mar#|#apr#|#may#|#jun#|#jul#|#aug#|#sep#|#oct#|#nov#|#dec#")
-         .asPredicate();
+ private static final Predicate<String> ONLY_AN_INTEGER = Pattern.compile("^([1-9]|10|11|12)$")
+                                                                  .asMatchPredicate();
+ private static final Predicate<String> MONTH_NORMALIZED = Pattern
+         .compile("^(#jan#|#feb#|#mar#|#apr#|#may#|#jun#|#jul#|#aug#|#sep#|#oct#|#nov#|#dec#)$")
+         .asMatchPredicate();

Suggested Test Cases (MonthCheckerTest.java):

@Test
void rejectsMixedIntegerMonthBibTeX() {
    checker = new MonthChecker(biblatexContext);
    assertEquals(Optional.of("should be an integer or normalized"), checker.checkValue("1abc"));
}

@Test
void rejectsPartialNormalizedMonth() {
    checker = new MonthChecker(bibtexContext);
    assertEquals(Optional.of("should be normalized"), checker.checkValue("#jan# trailing"));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions