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)
Steps to reproduce the behaviour
- Edit a BibTeX entry and set the
month field to an invalid mixed-string value like "1abc" or "#jan# foobar".
- Run JabRef's integrity check.
- 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"));
}
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)
Steps to reproduce the behaviour
monthfield to an invalid mixed-string value like"1abc"or"#jan# foobar".Technical Root Cause:
MonthCheckerusesPattern.compile(...).asPredicate()for bothONLY_AN_INTEGERandMONTH_NORMALIZED. TheasPredicate()method in Java usesMatcher.find()internally, meaning it performs a substring / partial match, not a full-string match."#jan# foobar"passesMONTH_NORMALIZEDbecause#jan#is found as a substring."1abc"passesONLY_AN_INTEGERbecause"1"is found.Appendix
Proposed Fix:
In
jablib/src/main/java/org/jabref/logic/integrity/MonthChecker.java:Switch from
asPredicate()toasMatchPredicate()(which usesMatcher.matches()) and add boundary anchors to enforce full-string matching:Suggested Test Cases (
MonthCheckerTest.java):