Skip to content

Commit

Permalink
Fix journal abbbrev checker for curly braces
Browse files Browse the repository at this point in the history
Escape any curly braces
Also use latex free fields


Fixes #9475
Fixes #9503
  • Loading branch information
Siedlerchr committed Dec 28, 2022
1 parent 7fc7361 commit 2628b59
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- The tab "deprecated fields" is shown in biblatex-mode only. [#7757](https://github.com/JabRef/jabref/issues/7757)
- We fixed an issue where the last opened libraries were not remembered when a new unsaved libray was open as well [#9190](https://github.com/JabRef/jabref/issues/9190)
- We fixed an issue where no context menu for the group "All entries" was present [forum#3682](https://discourse.jabref.org/t/how-sort-groups-a-z-not-subgroups/3682)
- We fixed an issue where extra curly braces in some fields would trigger an exception when selecting the entry or doing an integrity check [#9475](https://github.com/JabRef/jabref/issues/9475), [#9503](https://github.com/JabRef/jabref/issues/9503)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public boolean unabbreviate(BibDatabase database, BibEntry entry, Field field, C
return true;
}

String text = entry.getField(field).get();
String text = entry.getLatexFreeField(field).get();
String origText = text;
if (database != null) {
text = database.resolveForStrings(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean isKnownName(String journalName) {
}

return fullToAbbreviation.containsKey(journal) || abbreviationToFull.containsKey(journal)
|| findDottedAbbrFromDotless(journal).length() > 0;
|| (findDottedAbbrFromDotless(journal).length() > 0);
}

/**
Expand All @@ -80,7 +80,7 @@ public boolean isAbbreviatedName(String journalName) {

return customAbbreviations.stream().anyMatch(abbreviation -> isMatchedAbbreviated(journal, abbreviation))
|| abbreviationToFull.containsKey(journal)
|| (isMoreThanTwoWords && findDottedAbbrFromDotless(journal).length() > 0);
|| (isMoreThanTwoWords && (findDottedAbbrFromDotless(journal).length() > 0));
}

public String findDottedAbbrFromDotless(String journalName) {
Expand All @@ -94,6 +94,8 @@ public String findDottedAbbrFromDotless(String journalName) {
// check for a dot-less abbreviation
if (!DOT.matcher(journalName).find()) {
// use dot-less abbr to find full name using regex
journalName = journalName.replace("{", "\\{");
journalName = journalName.replace("}", "\\}");
String[] journalSplit = journalName.split(" ");

for (int i = 0; i < journalSplit.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,19 @@ void testJournalDotlessAbbreviation() {
.withField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces");
assertEquals(expectedAbbreviatedJournalEntry, abbreviatedJournalEntry);
}

@Test
void testJournalDotlessAbbreviationWithCurlyBraces() {
BibDatabase bibDatabase = new BibDatabase();
JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository();
UndoableUnabbreviator undoableUnabbreviator = new UndoableUnabbreviator(journalAbbreviationRepository);

BibEntry abbreviatedJournalEntry = new BibEntry(StandardEntryType.Article);
abbreviatedJournalEntry.setField(StandardField.JOURNAL, "{ACS Appl Mater Interfaces}");

undoableUnabbreviator.unabbreviate(bibDatabase, abbreviatedJournalEntry, StandardField.JOURNAL, new CompoundEdit());
BibEntry expectedAbbreviatedJournalEntry = new BibEntry(StandardEntryType.Article)
.withField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces");
assertEquals(expectedAbbreviatedJournalEntry, abbreviatedJournalEntry);
}
}

0 comments on commit 2628b59

Please sign in to comment.