Skip to content

Commit aa60dd6

Browse files
authored
Fix for entering a backslash in the custom entry preview dialog (#7851)
1 parent 6a501e7 commit aa60dd6

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
111111
- We fixed an issue where the RFC fetcher is not compatible with the draft [7305](https://github.com/JabRef/jabref/issues/7305)
112112
- We fixed an issue where duplicate files (both file names and contents are the same) is downloaded and add to linked files [#6197](https://github.com/JabRef/jabref/issues/6197)
113113
- We fixed an issue where changing the appearance of the preview tab did not trigger a restart warning. [#5464](https://github.com/JabRef/jabref/issues/5464)
114+
- We fixed an issue where editing "Custom preview style" triggers exception. [#7526](https://github.com/JabRef/jabref/issues/7526)
114115
- We fixed an issue where a title with multiple applied formattings in EndNote was not imported correctly [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)
115116
- We fixed an issue where a `report` in EndNote was imported as `article` [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)
116117
- We fixed an issue where the field `publisher` in EndNote was not imported in JabRef [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)

src/main/java/org/jabref/logic/layout/LayoutHelper.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private void doBracketedOptionField() throws IOException {
188188
}
189189
}
190190

191-
private void parse() throws IOException, StringIndexOutOfBoundsException {
191+
private void parse() throws IOException {
192192
skipWhitespace();
193193

194194
int c;
@@ -254,11 +254,15 @@ private void parseField() throws IOException {
254254

255255
if (name.isEmpty()) {
256256
StringBuilder lastFive = new StringBuilder(10);
257-
for (StringInt entry : parsedEntries.subList(Math.max(0, parsedEntries.size() - 6),
258-
parsedEntries.size() - 1)) {
259-
lastFive.append(entry.s);
257+
if (parsedEntries.isEmpty()) {
258+
lastFive.append("unknown");
259+
} else {
260+
for (StringInt entry : parsedEntries.subList(Math.max(0, parsedEntries.size() - 6),
261+
parsedEntries.size() - 1)) {
262+
lastFive.append(entry.s);
263+
}
260264
}
261-
throw new StringIndexOutOfBoundsException(
265+
throw new IOException(
262266
"Backslash parsing error near \'" + lastFive.toString().replace("\n", " ") + '\'');
263267
}
264268

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.jabref.logic.layout;
2+
3+
import java.io.IOException;
4+
import java.io.StringReader;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
import static org.mockito.Mockito.mock;
11+
12+
class LayoutHelperTest {
13+
14+
@Test
15+
public void backslashDoesNotTriggerException() {
16+
StringReader stringReader = new StringReader("\\");
17+
LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class);
18+
LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences);
19+
assertThrows(IOException.class, () -> layoutHelper.getLayoutFromText());
20+
}
21+
22+
@Test
23+
public void unbalancedBeginEndIsParsed() throws Exception {
24+
StringReader stringReader = new StringReader("\\begin{doi}, DOI: \\doi");
25+
LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class);
26+
LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences);
27+
Layout layout = layoutHelper.getLayoutFromText();
28+
assertNotNull(layout);
29+
}
30+
31+
@Test
32+
public void minimalExampleWithDoiGetsParsed() throws Exception {
33+
StringReader stringReader = new StringReader("\\begin{doi}, DOI: \\doi\\end{doi}");
34+
LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class);
35+
LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences);
36+
Layout layout = layoutHelper.getLayoutFromText();
37+
assertNotNull(layout);
38+
}
39+
}

0 commit comments

Comments
 (0)