Skip to content

Commit

Permalink
open office csv format correction for abstract column (#9570)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravitwr authored Jan 22, 2023
1 parent b575aae commit 00c943d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- For portable versions, the `.deb` file now works on plain debian again. [#9472](https://github.com/JabRef/jabref/issues/9472)
- We fixed an issue where the download of linked online files failed after an import of entries for certain urls. [#9518](https://github.com/JabRef/jabref/issues/9518)
- We fixed an issue where an exception occured when manually downloading a file from an URL in the entry editor. [#9521](https://github.com/JabRef/jabref/issues/9521)
- We fixed an issue with open office csv file formatting where commas in the abstract field where not escaped. [#9087][https://github.com/JabRef/jabref/issues/9087]
- We fixed an issue with deleting groups where subgroups different from the selected group were deleted. [#9281][https://github.com/JabRef/jabref/issues/9281]

## [5.8] - 2022-12-18
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/layout/LayoutEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.jabref.logic.layout.format.RemoveTilde;
import org.jabref.logic.layout.format.RemoveWhitespace;
import org.jabref.logic.layout.format.Replace;
import org.jabref.logic.layout.format.ReplaceWithEscapedDoubleQuotes;
import org.jabref.logic.layout.format.RisAuthors;
import org.jabref.logic.layout.format.RisKeywords;
import org.jabref.logic.layout.format.RisMonth;
Expand Down Expand Up @@ -475,6 +476,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) {
case "Markdown" -> new MarkdownFormatter();
case "CSLType" -> new CSLType();
case "ShortMonth" -> new ShortMonthFormatter();
case "ReplaceWithEscapedDoubleQuotes" -> new ReplaceWithEscapedDoubleQuotes();
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jabref.logic.layout.format;

import org.jabref.logic.layout.LayoutFormatter;

public class ReplaceWithEscapedDoubleQuotes implements LayoutFormatter {
@Override
public String format(String fieldText) {
StringBuilder builder = new StringBuilder(fieldText.length());

for (char c : fieldText.toCharArray()) {
if (c == '\"') {
builder.append("\"\"");
} else {
builder.append(c);
}
}
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
\format[GetOpenOfficeType]{\entrytype},"\begin{isbn}\isbn\end{isbn}","\citationkey","\format[Authors(LastFirst,FullName,Semicolon,Semicolon)]{\author}","\format[RemoveBrackets,RemoveWhitespace]{\title}","\journal",\volume,\number,"\month","\pages",\year,"\address","\note","\url","\booktitle","\chapter","\edition","\series","\format[Authors(LastFirst,FullName,Semicolon,Semicolon)]{\editor}","\publisher","\begin{reporttype}\reporttype\end{reporttype}","\howpublished","\institution","\organization","\school","\annote","\format[Replace(\n, )]{\abstract}","\comment","\keywords","\format[FileLink(pdf)]{\file}","\key"
\format[GetOpenOfficeType]{\entrytype},"\begin{isbn}\isbn\end{isbn}","\citationkey","\format[Authors(LastFirst,FullName,Semicolon,Semicolon)]{\author}","\format[RemoveBrackets,RemoveWhitespace]{\title}","\journal",\volume,\number,"\month","\pages",\year,"\address","\note","\url","\booktitle","\chapter","\edition","\series","\format[Authors(LastFirst,FullName,Semicolon,Semicolon)]{\editor}","\publisher","\begin{reporttype}\reporttype\end{reporttype}","\howpublished","\institution","\organization","\school","\annote","\format[Replace(\n, ),ReplaceWithEscapedDoubleQuotes]{\abstract}","\comment","\keywords","\format[FileLink(pdf)]{\file}","\key"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.jabref.logic.formatter.bibtexfields;

import org.jabref.logic.layout.format.ReplaceWithEscapedDoubleQuotes;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ReplaceWithEscapedDoubleQuotesTest {

private ReplaceWithEscapedDoubleQuotes formatter;

@BeforeEach
public void setUp() {
formatter = new ReplaceWithEscapedDoubleQuotes();
}

@Test
public void replacingSingleDoubleQuote() {
assertEquals("single \"\"double quote", formatter.format("single \"double quote"));
}

@Test
public void replacingMultipleDoubleQuote() {
assertEquals("multiple \"\"double\"\" quote", formatter.format("multiple \"double\" quote"));
}

@Test
public void replacingSingleDoubleQuoteHavingCommas() {
assertEquals("this \"\"is\"\", a test", formatter.format("this \"is\", a test"));
}

@Test
public void doNothing() {
assertEquals("this is a test", formatter.format("this is a test"));
}
}

0 comments on commit 00c943d

Please sign in to comment.