Skip to content

Commit

Permalink
Fix "&" on previews (#5786)
Browse files Browse the repository at this point in the history
* Removes unnecessary escape on HTMLChars

* Reverts change on HTMLChars.java and removes HTML formatting from the CSL adapter.

* Adds test to check for ampersand handling
  • Loading branch information
José Jesús Sinohui Fernández authored and tobiasdiez committed Dec 31, 2019
1 parent 371a863 commit 9474f5a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 9474f5a

Please sign in to comment.