diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c4869a0d16..6e5a7853897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Fixed - We fixed an issue where the added protected term has unwanted leading and trailing whitespaces, where the formatted text has unwanted empty brackets and where the word at the cursor in the textbox can be added to the list [#10415](https://github.com/JabRef/jabref/issues/10415). +- We fixed an issue where in the merge dialog the file field of entries was not correctly merged when the first and second entry both contained values inside the file field [#10572](https://github.com/JabRef/jabref/issues/10572) ### Removed diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/fieldsmerger/FileMerger.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/fieldsmerger/FileMerger.java index 4b4e2034226..91063b931f1 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/fieldsmerger/FileMerger.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/fieldsmerger/FileMerger.java @@ -1,8 +1,6 @@ package org.jabref.gui.mergeentries.newmergedialog.fieldsmerger; import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.jabref.logic.bibtex.FileFieldWriter; import org.jabref.logic.importer.util.FileFieldParser; @@ -25,10 +23,9 @@ public String merge(String filesA, String filesB) { } else { List linkedFilesA = FileFieldParser.parse(filesA); List linkedFilesB = FileFieldParser.parse(filesB); - // TODO: If one of the linked files list is empty then the its string value is malformed. - return Stream.concat(linkedFilesA.stream(), linkedFilesB.stream()) - .map(FileFieldWriter::getStringRepresentation) - .collect(Collectors.joining()); + + linkedFilesA.addAll(linkedFilesB); + return FileFieldWriter.getStringRepresentation(linkedFilesA); } } } diff --git a/src/test/java/org/jabref/gui/mergeentries/newmergedialog/fieldsmerger/FileMergerTest.java b/src/test/java/org/jabref/gui/mergeentries/newmergedialog/fieldsmerger/FileMergerTest.java new file mode 100644 index 00000000000..164015cbfdc --- /dev/null +++ b/src/test/java/org/jabref/gui/mergeentries/newmergedialog/fieldsmerger/FileMergerTest.java @@ -0,0 +1,36 @@ +package org.jabref.gui.mergeentries.newmergedialog.fieldsmerger; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class FileMergerTest { + FileMerger fileMerger = new FileMerger(); + + /** + * Test the following cases + * nullvalues + * emptyString for FileB + * emptyString for FileA + * FileA and FileB are valid strings and are separated by semicolon + * + * @param expect Expected value + * @param fileA File string a + * @param fileB File String b + */ + @ParameterizedTest + @CsvSource(textBlock = """ + ,,, + FileA,FileA, + FileA,FileA,'' + FileB, ,FileB + FileB,'',FileB + :A2012 -A.pdf:PDF;B2013 - B.pdf:PDF:,:A2012 -A.pdf:PDF,B2013 - B.pdf:PDF + :A2012 -A.pdf:;B2013 - B.pdf:PDF:,A2012 -A.pdf,B2013 - B.pdf:PDF + :A2012 -A.pdf:;:asdf:,A2012 -A.pdf,asdf + """) + void testMerge(String expect, String fileA, String fileB) { + assertEquals(expect, fileMerger.merge(fileA, fileB)); + } +}