diff --git a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index 9d743121766..8c6ec743af7 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -711,13 +711,16 @@ private static String keepLettersAndDigitsOnly(String in) { * Gets the last name of the first author/editor * * @param authorList an {@link AuthorList} - * @return the surname of an author/editor or "" if no author was found This method is guaranteed to never return - * null. + * @return the surname of an author/editor or the von part if no lastname is prsent or "" if no author was found or both firstname+lastname are empty + * This method is guaranteed to never return null. */ private static String firstAuthor(AuthorList authorList) { return authorList.getAuthors().stream() .findFirst() - .flatMap(Author::getLast).orElse(""); + .flatMap(author -> author.getLast().isPresent() ? author.getLast() : author.getVon()) + .orElse(""); + + } /** @@ -967,7 +970,7 @@ private static String authshort(AuthorList authorList) { if (numberOfAuthors == 1) { author.append(authorList.getAuthor(0).getLast().orElse("")); } else if (numberOfAuthors >= 2) { - for (int i = 0; i < numberOfAuthors && i < 3; i++) { + for (int i = 0; (i < numberOfAuthors) && (i < 3); i++) { author.append(authNofMth(authorList, 1, i + 1)); } if (numberOfAuthors > 3) { @@ -1004,7 +1007,7 @@ private static String authshort(AuthorList authorList) { * to "" be returned. */ private static String authIniN(AuthorList authorList, int n) { - if (n <= 0 || authorList.isEmpty()) { + if ((n <= 0) || authorList.isEmpty()) { return ""; } @@ -1233,7 +1236,7 @@ private static String generateInstitutionKey(String content) { } } else if ((tokenTypes.contains(Institution.SCHOOL) || tokenTypes.contains(Institution.DEPARTMENT)) - && institutionNameTokens.length > 1) { + && (institutionNameTokens.length > 1)) { // School is an abbreviation of all the words beginning with a // capital letter excluding: department, school and faculty words. StringBuilder schoolSB = new StringBuilder(); diff --git a/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java b/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java index d33045c890d..626563158c2 100644 --- a/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java +++ b/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java @@ -1134,4 +1134,18 @@ void generateKeyWithFallbackField() { assertEquals("2021", generateKey(bibEntry, "[title:([EPRINT:([YEAR])])]")); } + + @Test + void generateKeyWithLowercaseAuthorLastnameUseVonPart() { + BibEntry entry = createABibEntryAuthor("Stéphane d'Ascoli"); + entry.setField(StandardField.YEAR, "2021"); + assertEquals("dAscoli2021", generateKey(entry, "[auth][year]")); + } + + @Test + void generateKeyWithLowercaseAuthorWithVonAndLastname() { + BibEntry entry = createABibEntryAuthor("Michiel van den Brekel"); + entry.setField(StandardField.YEAR, "2021"); + assertEquals("Brekel2021", generateKey(entry, "[auth][year]")); + } }