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 5359: Writing of Editor field is duplicated #5392

Merged
merged 4 commits into from
Oct 6, 2019
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
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