Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Citation keygen: Return vonPart if lastName is empty #8634

Merged
merged 2 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 "";
}

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]"));
}
}