Skip to content

Commit f2ac9f0

Browse files
rishivardhanmmkoppor
andauthoredMar 17, 2025··
considering multiple spaces as separate user block by replacing it with " and " (#12757)
* considering multiple spaces as separate user block by replacing it with " and " * considering multiple spaces as separate user block by replacing it with " and " * considering multiple spaces as separate user block by replacing it with " and " * considering multiple spaces as separate user block by replacing it with " and " * considering multiple spaces as separate user block by replacing it with " and " * Revert "considering multiple spaces as separate user block by replacing it with " and "" This reverts commit ca6e337 * considering multiple spaces as separate user block by replacing it with " and " * considering multiple spaces as separate user block by replacing it with " and " * considering multiple spaces as separate user block by replacing it with " and " * Update CHANGELOG.md Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> * considering multiple spaces as separate user block by replacing it with " and " --------- Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
1 parent bb291ac commit f2ac9f0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
2222
- We added an integrity check if a URL appears in a title. [#12354](https://github.com/JabRef/jabref/issues/12354)
2323
- We added a feature for enabling drag-and-drop of files into groups [#12540](https://github.com/JabRef/jabref/issues/12540)
2424
- 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)
25+
- 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)
2526

2627
### Changed
2728

‎src/main/java/org/jabref/logic/importer/AuthorListParser.java

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public class AuthorListParser {
3939

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

42+
private static final Pattern MULTIPLE_SPACE_PATTERN = Pattern.compile("\\s{2,}");
43+
44+
private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\s*\\n\\s*");
45+
4246
/**
4347
* the raw bibtex author/editor field
4448
*/
@@ -100,6 +104,10 @@ private record SimpleNormalFormResult(String authors, boolean andOthersPresent)
100104

101105
private static SimpleNormalFormResult getSimpleNormalForm(String listOfNames) {
102106
listOfNames = listOfNames.replace(" -", "-").trim();
107+
if (!listOfNames.contains(",") && (MULTIPLE_SPACE_PATTERN.matcher(listOfNames).find() || listOfNames.contains("\n"))) {
108+
listOfNames = NEW_LINE_PATTERN.matcher(listOfNames).replaceAll(" and ");
109+
listOfNames = MULTIPLE_SPACE_PATTERN.matcher(listOfNames).replaceAll(" and ");
110+
}
103111

104112
// Handling of "and others"
105113
// Remove it from the list; it will be added at the very end of this method as special Author.OTHERS

‎src/test/java/org/jabref/logic/importer/AuthorListParserTest.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,37 @@ private static Stream<Arguments> parseMultipleCorrectly() {
7979
new Author("Thomas", "T.", null, "Lai", null)
8080
),
8181
"U, Vivian and Lai, Thomas"
82-
)
82+
),
83+
Arguments.of(
84+
AuthorList.of(
85+
new Author("I.", "I.", null, "Podadera", null),
86+
new Author("J. M.", "J. M.", null, "Carmona", null),
87+
new Author("A.", "A.", null, "Ibarra", null),
88+
new Author("J.", "J.", null, "Molla", null)
89+
),
90+
"I. Podadera J. M. Carmona A. Ibarra J. Molla"),
91+
Arguments.of(
92+
AuthorList.of(
93+
new Author("Alexander", "A.", null, "Artemenko", null),
94+
new Author("I.", "I.", null, "Podadera", null),
95+
new Author("J. M.", "J. M.", null, "Carmona", null)
96+
),
97+
"""
98+
Alexander Artemenko
99+
I. Podadera
100+
J. M. Carmona
101+
"""),
102+
Arguments.of(
103+
AuthorList.of(
104+
new Author("First1", "F.", null, "Last1", null),
105+
new Author("First2", "F.", null, "Last2", null),
106+
new Author("First3", "F.", null, "Last3", null)
107+
),
108+
"""
109+
First1 Last1
110+
First2 Last2
111+
First3 Last3
112+
""")
83113
);
84114
}
85115

0 commit comments

Comments
 (0)
Please sign in to comment.