Skip to content

Commit

Permalink
Fix file field merging (JabRef#10573)
Browse files Browse the repository at this point in the history
Add test

Fixes JabRef#10572
  • Loading branch information
Siedlerchr authored Oct 24, 2023
1 parent f6334e9 commit 956e9f6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,10 +23,9 @@ public String merge(String filesA, String filesB) {
} else {
List<LinkedFile> linkedFilesA = FileFieldParser.parse(filesA);
List<LinkedFile> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 956e9f6

Please sign in to comment.