From 4bbb1530c4ea8d0c67523808246bed9ea825baad Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Sat, 5 Oct 2019 10:01:28 +0200 Subject: [PATCH 1/3] add (failing) test for #5359 --- .../logic/bibtex/BibEntryWriterTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java index 3c158a64d53..5b2d91b77c3 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java @@ -106,6 +106,64 @@ void writeEntryWithFile() throws Exception { + "}" + OS.NEWLINE, stringWriter.toString()); } + @Test + void writeEntryWithOrField() throws Exception { + StringWriter stringWriter = new StringWriter(); + + BibEntry entry = new BibEntry(StandardEntryType.InBook); + //set an required OR field (author/editor) + entry.setField(StandardField.EDITOR, "Foo Bar"); + entry.setField(StandardField.JOURNAL, "International Journal of Something"); + //set an optional field + entry.setField(StandardField.NUMBER, "1"); + entry.setField(StandardField.NOTE, "some note"); + + writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX); + + String actual = stringWriter.toString(); + + // @formatter:off + String expected = OS.NEWLINE + "@InBook{," + OS.NEWLINE + + " editor = {Foo Bar}," + OS.NEWLINE + + " note = {some note}," + OS.NEWLINE + + " number = {1}," + OS.NEWLINE + + " journal = {International Journal of Something}," + OS.NEWLINE + + "}" + OS.NEWLINE; + // @formatter:on + + assertEquals(expected, actual); + } + + @Test + void writeEntryWithOrFieldBothFieldsPresent() throws Exception { + StringWriter stringWriter = new StringWriter(); + + BibEntry entry = new BibEntry(StandardEntryType.InBook); + //set an required OR field with both fields(author/editor) + entry.setField(StandardField.AUTHOR, "Foo Thor"); + entry.setField(StandardField.EDITOR, "Edi Bar"); + entry.setField(StandardField.JOURNAL, "International Journal of Something"); + //set an optional field + entry.setField(StandardField.NUMBER, "1"); + entry.setField(StandardField.NOTE, "some note"); + + writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX); + + String actual = stringWriter.toString(); + + // @formatter:off + String expected = OS.NEWLINE + "@InBook{," + OS.NEWLINE + + " author = {Foo Thor}," + OS.NEWLINE + + " editor = {Edi Bar}," + OS.NEWLINE + + " note = {some note}," + OS.NEWLINE + + " number = {1}," + OS.NEWLINE + + " journal = {International Journal of Something}," + OS.NEWLINE + + "}" + OS.NEWLINE; + // @formatter:on + + assertEquals(expected, actual); + } + @Test public void writeReallyUnknownTypeTest() throws Exception { String expected = OS.NEWLINE + "@Reallyunknowntype{test," + OS.NEWLINE + From 1ccc1ab00bc95b3749e4cc40aabff09c64287d93 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Sat, 5 Oct 2019 10:09:31 +0200 Subject: [PATCH 2/3] fixes #5359 - correction writing of OrFields in BibEntryWriter --- src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java b/src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java index 4169df2da8f..2f1bce49674 100644 --- a/src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java +++ b/src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java @@ -111,7 +111,7 @@ private void writeRequiredFieldsFirstRemainingFieldsSecond(BibEntry entry, Write for (OrFields value : type.get().getRequiredFields()) { for (Field field : value) { writeField(entry, out, field, indentation); - written.add(value.getPrimary()); + written.add(field); } } // Then optional fields. From 4a56bc6fc9e3ef6d8e56a0c39d87a2045e0fb577 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Sat, 5 Oct 2019 10:15:06 +0200 Subject: [PATCH 3/3] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b71f0091dcd..acc84781118 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an exception which occured when trying to open a non existing file from the "Recent files"-menu [#5334](https://github.com/JabRef/jabref/issues/5334) - The context menu for fields in the entry editor is back. [#5254](https://github.com/JabRef/jabref/issues/5254) - We fixed an exception which occurred when trying to open a non existing file from the "Recent files"-menu [#5334](https://github.com/JabRef/jabref/issues/5334) +- We fixed a problem where the "editor" information has been duplicated during saving a .bib-Database. [#5359](https://github.com/JabRef/jabref/issues/5359) ### Removed