diff --git a/CHANGELOG b/CHANGELOG index f5fd05d74d9..c8082829be3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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. diff --git a/src/main/java/net/sf/jabref/PreviewPanel.java b/src/main/java/net/sf/jabref/PreviewPanel.java index 6a4585a0bf5..00c5d30d448 100644 --- a/src/main/java/net/sf/jabref/PreviewPanel.java +++ b/src/main/java/net/sf/jabref/PreviewPanel.java @@ -364,6 +364,8 @@ public void setEntry(BibtexEntry newEntry) { try { readLayout(); update(); + } catch (StringIndexOutOfBoundsException ex) { + throw ex; } catch (Exception ex) { ex.printStackTrace(); } diff --git a/src/main/java/net/sf/jabref/PreviewPrefsTab.java b/src/main/java/net/sf/jabref/PreviewPrefsTab.java index a454f9c0ffa..7730700e4c8 100644 --- a/src/main/java/net/sf/jabref/PreviewPrefsTab.java +++ b/src/main/java/net/sf/jabref/PreviewPrefsTab.java @@ -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); + } } }); } diff --git a/src/main/java/net/sf/jabref/export/layout/LayoutHelper.java b/src/main/java/net/sf/jabref/export/layout/LayoutHelper.java index d4152be838a..f08a97911de 100644 --- a/src/main/java/net/sf/jabref/export/layout/LayoutHelper.java +++ b/src/main/java/net/sf/jabref/export/layout/LayoutHelper.java @@ -20,6 +20,8 @@ import java.io.Reader; import java.util.Vector; +import javax.swing.JOptionPane; + /** * Helper class to get a Layout object. @@ -62,8 +64,8 @@ public LayoutHelper(Reader in) } public Layout getLayoutFromText(String classPrefix) throws Exception - { - parse(); + { + parse(); StringInt si; @@ -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; @@ -288,7 +290,7 @@ else if (c == '"') { return null; } - private Object parse() throws IOException { + private Object parse() throws IOException, StringIndexOutOfBoundsException { skipWhitespace(); int c; @@ -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) @@ -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")) { @@ -385,7 +398,7 @@ else if (name.equalsIgnoreCase("begingroup")) return; } } - else if (name.charAt(0) == 'f') + else if (firstLetter == 'f') { if (name.equalsIgnoreCase("format")) { @@ -422,7 +435,7 @@ else if (name.equalsIgnoreCase("filepath")) return; } } - else if (name.charAt(0) == 'e') + else if (firstLetter == 'e') { if (name.equalsIgnoreCase("end")) {