Skip to content

Commit

Permalink
Fix for entering a backslash in the custom entry preview dialog (#7851)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor authored Jun 27, 2021
1 parent 6a501e7 commit aa60dd6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where the RFC fetcher is not compatible with the draft [7305](https://github.com/JabRef/jabref/issues/7305)
- 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)
- 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)
- We fixed an issue where editing "Custom preview style" triggers exception. [#7526](https://github.com/JabRef/jabref/issues/7526)
- 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)
- 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)
- 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)
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/jabref/logic/layout/LayoutHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void doBracketedOptionField() throws IOException {
}
}

private void parse() throws IOException, StringIndexOutOfBoundsException {
private void parse() throws IOException {
skipWhitespace();

int c;
Expand Down Expand Up @@ -254,11 +254,15 @@ private void parseField() throws IOException {

if (name.isEmpty()) {
StringBuilder lastFive = new StringBuilder(10);
for (StringInt entry : parsedEntries.subList(Math.max(0, parsedEntries.size() - 6),
parsedEntries.size() - 1)) {
lastFive.append(entry.s);
if (parsedEntries.isEmpty()) {
lastFive.append("unknown");
} else {
for (StringInt entry : parsedEntries.subList(Math.max(0, parsedEntries.size() - 6),
parsedEntries.size() - 1)) {
lastFive.append(entry.s);
}
}
throw new StringIndexOutOfBoundsException(
throw new IOException(
"Backslash parsing error near \'" + lastFive.toString().replace("\n", " ") + '\'');
}

Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/jabref/logic/layout/LayoutHelperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jabref.logic.layout;

import java.io.IOException;
import java.io.StringReader;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

class LayoutHelperTest {

@Test
public void backslashDoesNotTriggerException() {
StringReader stringReader = new StringReader("\\");
LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class);
LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences);
assertThrows(IOException.class, () -> layoutHelper.getLayoutFromText());
}

@Test
public void unbalancedBeginEndIsParsed() throws Exception {
StringReader stringReader = new StringReader("\\begin{doi}, DOI: \\doi");
LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class);
LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences);
Layout layout = layoutHelper.getLayoutFromText();
assertNotNull(layout);
}

@Test
public void minimalExampleWithDoiGetsParsed() throws Exception {
StringReader stringReader = new StringReader("\\begin{doi}, DOI: \\doi\\end{doi}");
LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class);
LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences);
Layout layout = layoutHelper.getLayoutFromText();
assertNotNull(layout);
}
}

0 comments on commit aa60dd6

Please sign in to comment.