diff --git a/CHANGELOG.md b/CHANGELOG.md index 3886e8993e5..563418337ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ### Fixed +- We fixed an issue where the author's lastname was not used for the citation key generation if it started with a lowercase letter [#8601](https://github.com/JabRef/jabref/issues/8601) - We fixed an issue where custom "Protected terms" files were missing after a restart of JabRef [#8608](https://github.com/JabRef/jabref/issues/8608) - We fixed an issue where JabRef could not start due to a missing directory for the fulltex index [#8579](https://github.com/JabRef/jabref/issues/8579) - We fixed an issue where long article numbers in the `pages` field would cause an exception and preventing the citation style to display [#8381](https://github.com/JabRef/jabref/issues/8381), [citeproc-java](https://github.com/michel-kraemer/citeproc-java/issues/114) diff --git a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index 9d743121766..ea7615db8bd 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -711,13 +711,14 @@ 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 +968,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 +1005,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 +1234,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]")); + } }