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

considering multiple spaces as separate user block by replacing it with " and " #12757

Merged
merged 12 commits into from
Mar 17, 2025
Merged
Changes from 10 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
@@ -21,6 +21,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added an integrity check if a URL appears in a title. [#12354](https://github.com/JabRef/jabref/issues/12354)
- We added a feature for enabling drag-and-drop of files into groups [#12540](https://github.com/JabRef/jabref/issues/12540)
- We added support for reordering keywords via drag and drop, automatic alphabetical ordering, and improved pasting and editing functionalities in the keyword editor. [#10984](https://github.com/JabRef/jabref/issues/10984)
- We added a new functionality where author names having multiple spaces in-between will be considered as separate user block as it does for " and ". [#12701](https://github.com/JabRef/jabref/issues/12701)

### Changed

8 changes: 8 additions & 0 deletions src/main/java/org/jabref/logic/importer/AuthorListParser.java
Original file line number Diff line number Diff line change
@@ -39,6 +39,10 @@ public class AuthorListParser {

private static final Pattern STARTS_WITH_CAPITAL_LETTER_DOT_OR_DASH = Pattern.compile("^[A-Z](\\.[ -]| ?-)");

private static final Pattern multipleSpacesPattern = Pattern.compile("\\s{2,}");

private static final Pattern newlinePattern = Pattern.compile("\\s*\\n\\s*");

/**
* the raw bibtex author/editor field
*/
@@ -100,6 +104,10 @@ private record SimpleNormalFormResult(String authors, boolean andOthersPresent)

private static SimpleNormalFormResult getSimpleNormalForm(String listOfNames) {
listOfNames = listOfNames.replace(" -", "-").trim();
if (!listOfNames.contains(",") && (multipleSpacesPattern.matcher(listOfNames).find() || listOfNames.contains("\n"))) {
listOfNames = newlinePattern.matcher(listOfNames).replaceAll(" and ");
listOfNames = multipleSpacesPattern.matcher(listOfNames).replaceAll(" and ");
}

// Handling of "and others"
// Remove it from the list; it will be added at the very end of this method as special Author.OTHERS
Original file line number Diff line number Diff line change
@@ -79,7 +79,26 @@ private static Stream<Arguments> parseMultipleCorrectly() {
new Author("Thomas", "T.", null, "Lai", null)
),
"U, Vivian and Lai, Thomas"
)
),
Arguments.of(
AuthorList.of(
new Author("I.", "I.", null, "Podadera", null),
new Author("J. M.", "J. M.", null, "Carmona", null),
new Author("A.", "A.", null, "Ibarra", null),
new Author("J.", "J.", null, "Molla", null)
),
"I. Podadera J. M. Carmona A. Ibarra J. Molla"),
Arguments.of(
AuthorList.of(
new Author("Alexander", "A.", null, "Artemenko", null),
new Author("I.", "I.", null, "Podadera", null),
new Author("J. M.", "J. M.", null, "Carmona", null)
),
"""
Alexander Artemenko
I. Podadera
J. M. Carmona
""")
);
}