Skip to content

Commit

Permalink
Merge pull request #12 from IngvarJackal/master
Browse files Browse the repository at this point in the history
BugFix for #959 "StringIndexOutOfBoundsException with invalid Preview text"
  • Loading branch information
Igor Steinmacher committed Jul 16, 2014
2 parents fc8c503 + 064f708 commit 582fbec
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Support FindFullText with ACS DOIs (pull request #9)
- Fixes groups and adds optional 2.9.2 save ordering (pull request #10)
- Fixes bug 880 "PubMed Import broken" (pull request #11 by vegeziel)
- Fixes bug #959 "StringIndexOutOfBoundsException with invalid Preview text" (pull request #12 by IngvarJackal)
2.10
- Made IEEEXploreFetcher author parsing work again.
- Added a few more characters in the HTML/Unicode to LaTeX conversion.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/sf/jabref/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ public void setEntry(BibtexEntry newEntry) {
try {
readLayout();
update();
} catch (StringIndexOutOfBoundsException ex) {
throw ex;
} catch (Exception ex) {
ex.printStackTrace();
}
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/net/sf/jabref/PreviewPrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,30 @@ public void actionPerformed(ActionEvent e) {
test1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
getTestEntry();
PreviewPanel testPanel = new PreviewPanel(null, entry, null , new MetaData(), layout1.getText());
testPanel.setPreferredSize(new Dimension(800, 350));
JOptionPane.showMessageDialog(null, testPanel, Globals.lang("Preview"),
JOptionPane.PLAIN_MESSAGE);
try {
PreviewPanel testPanel = new PreviewPanel(null, entry, null , new MetaData(), layout1.getText());
testPanel.setPreferredSize(new Dimension(800, 350));
JOptionPane.showMessageDialog(null, testPanel, Globals.lang("Preview"),
JOptionPane.PLAIN_MESSAGE);
} catch (StringIndexOutOfBoundsException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Parsing error: illegal backslash expression.\n" + ex.getMessage() + "\nLook at stderr for details.", "Parsing error", JOptionPane.WARNING_MESSAGE);
}
}
});

test2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
getTestEntry();
PreviewPanel testPanel = new PreviewPanel(null, entry, null, new MetaData(), layout2.getText());
testPanel.setPreferredSize(new Dimension(800, 350));
JOptionPane.showMessageDialog(null, new JScrollPane(testPanel),
Globals.lang("Preview"), JOptionPane.PLAIN_MESSAGE);
try {
PreviewPanel testPanel = new PreviewPanel(null, entry, null, new MetaData(), layout2.getText());
testPanel.setPreferredSize(new Dimension(800, 350));
JOptionPane.showMessageDialog(null, new JScrollPane(testPanel),
Globals.lang("Preview"), JOptionPane.PLAIN_MESSAGE);
} catch (StringIndexOutOfBoundsException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Parsing error: illegal backslash expression.\n" + ex.getMessage() + "\nLook at stderr for details.", "Parsing error", JOptionPane.WARNING_MESSAGE);
}
}
});
}
Expand Down
33 changes: 23 additions & 10 deletions src/main/java/net/sf/jabref/export/layout/LayoutHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.io.Reader;
import java.util.Vector;

import javax.swing.JOptionPane;


/**
* Helper class to get a Layout object.
Expand Down Expand Up @@ -62,8 +64,8 @@ public LayoutHelper(Reader in)
}

public Layout getLayoutFromText(String classPrefix) throws Exception
{
parse();
{
parse();

StringInt si;

Expand All @@ -76,7 +78,7 @@ public Layout getLayoutFromText(String classPrefix) throws Exception
si.s = si.s.trim().toLowerCase();
}
}

Layout layout = new Layout(parsedEntries, classPrefix);

return layout;
Expand Down Expand Up @@ -288,7 +290,7 @@ else if (c == '"') {
return null;
}

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

int c;
Expand Down Expand Up @@ -344,10 +346,11 @@ private Object parse() throws IOException {
/**
*
*/
private void parseField() throws IOException
private void parseField() throws IOException, StringIndexOutOfBoundsException
{
int c;
StringBuffer buffer = null;
char firstLetter = ' ';
String name;

while (!_eof)
Expand All @@ -365,11 +368,21 @@ private void parseField() throws IOException

//System.out.println("\n#" + (char) c);
name = buffer != null ? buffer.toString() : "";


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

//System.out.println("NAME:" + name);
buffer = null;

if (name.charAt(0) == 'b')
if (firstLetter == 'b')
{
if (name.equalsIgnoreCase("begin"))
{
Expand All @@ -385,7 +398,7 @@ else if (name.equalsIgnoreCase("begingroup"))
return;
}
}
else if (name.charAt(0) == 'f')
else if (firstLetter == 'f')
{
if (name.equalsIgnoreCase("format"))
{
Expand Down Expand Up @@ -422,7 +435,7 @@ else if (name.equalsIgnoreCase("filepath"))
return;
}
}
else if (name.charAt(0) == 'e')
else if (firstLetter == 'e')
{
if (name.equalsIgnoreCase("end"))
{
Expand Down

0 comments on commit 582fbec

Please sign in to comment.