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

Fix file field merging #10573

Merged
merged 1 commit into from
Oct 24, 2023
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 @@ -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));
}
}