Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where back navigation selected a deleted entry instead of skipping it. [#17353](https://github.com/JabRef/jabref/issues/17353)
- We fixed the linked file tooltip showing the old file name after renaming or moving the file. [#9277](https://github.com/JabRef/jabref/issues/9277)
- We fixed an issue where citationcount, day, and dayfiled columns were sorted alphabetically instead of numerically. [#17459](https://github.com/JabRef/jabref/issues/17459)
- We fixed an issue where the DocBook export wrote invalid XML for emoji and some math symbols. [#17747](https://github.com/JabRef/jabref/issues/17747)

## [6.0-beta.1] - 2026-09-21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,25 @@ private String restFormat(String toFormat) {

StringBuilder buffer = new StringBuilder(fieldText.length() * 2);

for (int i = 0; i < fieldText.length(); i++) {
int code = fieldText.charAt(i);
int i = 0;
while (i < fieldText.length()) {
int code = fieldText.codePointAt(i);

// Checking the case when the character is already escaped
// Just push "&#" to the buffer and keep going from the next char
if ((code == 38) && (fieldText.charAt(i + 1) == 35)) {
i += 2;
buffer.append("&#");
code = fieldText.charAt(i);
code = fieldText.codePointAt(i);
}

// TODO: Check whether > 125 is correct here or whether it should rather be >=
if ((code > 125) || forceReplace[code]) {
buffer.append("&#").append(code).append(';');
} else {
buffer.append((char) code);
buffer.appendCodePoint(code);
}
i += Character.charCount(code);
}
fieldText = buffer.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.time.LocalDate;
import java.util.List;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

Expand All @@ -28,13 +29,16 @@
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.mockito.Answers;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xmlunit.builder.Input;
import org.xmlunit.builder.Input.Builder;
import org.xmlunit.diff.DefaultNodeMatcher;
import org.xmlunit.diff.ElementSelectors;
import org.xmlunit.matchers.CompareMatcher;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

@Execution(ExecutionMode.SAME_THREAD)
Expand Down Expand Up @@ -86,4 +90,18 @@ void performExportForSingleEntry(@TempDir Path testFolder) throws IOException, S
.normalizeWhitespace()
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}

@Test
void titleWithEmojiIsValidXml(@TempDir Path testFolder) throws IOException, SaveException, ParserConfigurationException, TransformerException, SAXException {
Path path = testFolder.resolve("supplementaryCharacters.xml");
BibEntry entry = new BibEntry(StandardEntryType.Book)
.withField(StandardField.TITLE, "Smile 😀 and 𝛼");

exporter.export(databaseContext, path, List.of(entry));

Document document = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(path.toFile());
assertEquals("Smile 😀 and 𝛼", document.getElementsByTagName("citetitle").item(0).getTextContent());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.jabref.logic.layout.format;

import java.io.IOException;
import java.io.Reader;
import java.util.stream.Stream;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.jabref.logic.layout.LayoutFormatter;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

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

class XMLCharsTest {

private final LayoutFormatter formatter = new XMLChars();

private static Stream<Arguments> format() {
return Stream.of(
Arguments.of("normal", "normal"),
Arguments.of("&#233;", "é"),
Arguments.of("a &lt; b &gt; c", "a < b > c"),
Arguments.of("&#x0026;", "&"),
Arguments.of("&#120572;", "𝛼"),
Arguments.of("&#128512;", "😀"),
Arguments.of("Smile &#128512; and &#233;", "Smile 😀 and é"));
}

@ParameterizedTest
@MethodSource
void format(String expected, String input) {
assertEquals(expected, formatter.format(input));
}

@ParameterizedTest
@ValueSource(strings = {"normal", "é", "𝛼", "😀"})
void formattedTextIsParsableXml(String input) throws ParserConfigurationException, SAXException, IOException {
String xml = "<title>" + formatter.format(input) + "</title>";

Document document = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(new InputSource(Reader.of(xml)));

assertEquals(input, document.getDocumentElement().getTextContent());
}
}
Loading