Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for entering a backslash in the custom entry preview dialog #7851

Merged
merged 3 commits into from
Jun 27, 2021
Merged
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 @@ -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);
}
}