Skip to content

Commit

Permalink
Fix 5359: Writing of Editor field is duplicated (#5392)
Browse files Browse the repository at this point in the history
* add (failing) test for #5359

* fixes #5359 - correction writing of OrFields in BibEntryWriter

* add changelog entry
  • Loading branch information
matthiasgeiger authored and tobiasdiez committed Oct 6, 2019
1 parent 875b48e commit 9c7f7f6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ 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)
- We re-introduced the feature to switch between different preview styles. [#5221](https://github.com/JabRef/jabref/issues/5221)





### Removed


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
58 changes: 58 additions & 0 deletions src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down

0 comments on commit 9c7f7f6

Please sign in to comment.