From a1ccc4dbde103ace1ee5d6900c823664e82b89de Mon Sep 17 00:00:00 2001 From: Joseje Sinohui Date: Thu, 26 Dec 2019 12:04:51 -0700 Subject: [PATCH 1/3] Removes unnecessary escape on HTMLChars --- CHANGELOG.md | 1 + src/main/java/org/jabref/logic/layout/format/HTMLChars.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c3f7a0351f..cfb906d6b6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where the Medline fetcher was only working when JabRef was running from source [#5645](https://github.com/JabRef/jabref/issues/5645) - We fixed some visual issues in the dark theme [#5764](https://github.com/JabRef/jabref/pull/5764) [#5753](https://github.com/JabRef/jabref/issues/5753) - We fixed an issue where non-default previews didn't handle unicode characters. [#5779](https://github.com/JabRef/jabref/issues/5779) +- We fixed an issue where the ampersand character wasn't rendering correctly on previews.[#3840](https://github.com/JabRef/jabref/issues/3840) ### Removed diff --git a/src/main/java/org/jabref/logic/layout/format/HTMLChars.java b/src/main/java/org/jabref/logic/layout/format/HTMLChars.java index 5a713834096..0fb36324137 100644 --- a/src/main/java/org/jabref/logic/layout/format/HTMLChars.java +++ b/src/main/java/org/jabref/logic/layout/format/HTMLChars.java @@ -16,7 +16,7 @@ public class HTMLChars implements LayoutFormatter { @Override public String format(String inField) { int i; - String field = inField.replaceAll("&|\\\\&", "&") // Replace & and \& with & + String field = inField .replaceAll("[\\n]{2,}", "

") // Replace double line breaks with

.replace("\n", "
") // Replace single line breaks with
.replace("\\$", "$") // Replace \$ with $ From 24871a5a0efe2af919199308554903d57a17f1d8 Mon Sep 17 00:00:00 2001 From: Joseje Sinohui Date: Thu, 26 Dec 2019 14:07:02 -0700 Subject: [PATCH 2/3] Reverts change on HTMLChars.java and removes HTML formatting from the CSL adapter. --- src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java | 3 --- src/main/java/org/jabref/logic/layout/format/HTMLChars.java | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java b/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java index e5dbecafa2b..44a03e9f699 100644 --- a/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java +++ b/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java @@ -7,7 +7,6 @@ import java.util.Objects; import org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter; -import org.jabref.logic.layout.format.HTMLChars; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.Month; import org.jabref.model.entry.field.Field; @@ -93,13 +92,11 @@ private static CSLItemData bibEntryToCSLItemData(BibEntry bibEntry) { BibTeXEntry bibTeXEntry = new BibTeXEntry(new Key(bibEntry.getType().getName()), new Key(citeKey)); // Not every field is already generated into latex free fields - HTMLChars latexToHtmlConverter = new HTMLChars(); RemoveNewlinesFormatter removeNewlinesFormatter = new RemoveNewlinesFormatter(); for (Field key : bibEntry.getFieldMap().keySet()) { bibEntry.getField(key) .map(removeNewlinesFormatter::format) .map(LatexToUnicodeAdapter::format) - .map(latexToHtmlConverter::format) .ifPresent(value -> { if (StandardField.MONTH.equals(key)) { // Change month from #mon# to mon because CSL does not support the former format diff --git a/src/main/java/org/jabref/logic/layout/format/HTMLChars.java b/src/main/java/org/jabref/logic/layout/format/HTMLChars.java index 0fb36324137..5a713834096 100644 --- a/src/main/java/org/jabref/logic/layout/format/HTMLChars.java +++ b/src/main/java/org/jabref/logic/layout/format/HTMLChars.java @@ -16,7 +16,7 @@ public class HTMLChars implements LayoutFormatter { @Override public String format(String inField) { int i; - String field = inField + String field = inField.replaceAll("&|\\\\&", "&") // Replace & and \& with & .replaceAll("[\\n]{2,}", "

") // Replace double line breaks with

.replace("\n", "
") // Replace single line breaks with
.replace("\\$", "$") // Replace \$ with $ From 7c5cec54f4e16f9ea7086367a4e5c434caee3ed9 Mon Sep 17 00:00:00 2001 From: Joseje Sinohui Date: Mon, 30 Dec 2019 15:59:51 -0700 Subject: [PATCH 3/3] Adds test to check for ampersand handling --- .../citationstyle/CitationStyleGeneratorTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java index ecb7a1d6b37..63627b59809 100644 --- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java +++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java @@ -130,4 +130,16 @@ void testHandleDiacritics() { String citation = CitationStyleGenerator.generateCitation(entry, CitationStyle.getDefault()); assertEquals(expected, citation); } + + @Test + void testHandleAmpersand() { + String expectedCitation = "[1]B. Smith, B. Jones, and J. Williams, “&TitleTest&” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016.\n"; + BibEntry entry = TestEntry.getTestEntry(); + entry.setField(StandardField.TITLE, "“&TitleTest&”"); + String style = CitationStyle.getDefault().getSource(); + CitationStyleOutputFormat format = CitationStyleOutputFormat.TEXT; + + String actualCitation = CitationStyleGenerator.generateCitation(entry, style, format); + assertEquals(expectedCitation, actualCitation); + } }