diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c5604d6c2..5a5bb04267c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/org/jabref/logic/layout/LayoutEntry.java b/src/main/java/org/jabref/logic/layout/LayoutEntry.java index 2043953c218..495795417a5 100644 --- a/src/main/java/org/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/org/jabref/logic/layout/LayoutEntry.java @@ -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; @@ -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; }; } diff --git a/src/main/java/org/jabref/logic/layout/format/ReplaceWithEscapedDoubleQuotes.java b/src/main/java/org/jabref/logic/layout/format/ReplaceWithEscapedDoubleQuotes.java new file mode 100644 index 00000000000..059d9b0337c --- /dev/null +++ b/src/main/java/org/jabref/logic/layout/format/ReplaceWithEscapedDoubleQuotes.java @@ -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(); + } +} diff --git a/src/main/resources/resource/layout/openoffice/openoffice-csv.layout b/src/main/resources/resource/layout/openoffice/openoffice-csv.layout index 42f6e906329..d76ad31d0c9 100644 --- a/src/main/resources/resource/layout/openoffice/openoffice-csv.layout +++ b/src/main/resources/resource/layout/openoffice/openoffice-csv.layout @@ -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" diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceWithEscapedDoubleQuotesTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceWithEscapedDoubleQuotesTest.java new file mode 100644 index 00000000000..ed1f6bcf5bd --- /dev/null +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceWithEscapedDoubleQuotesTest.java @@ -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")); + } +}