Skip to content

Commit

Permalink
Be more robust in case of broken meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhard committed Jan 26, 2016
1 parent e8264fe commit ae9e874
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/net/sf/jabref/exporter/SaveActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ public SaveActions(MetaData metaData) {
setAvailableFormatters();

for (int i = 0; i < formatters.size(); i += 2) {
String field = formatters.get(i);
Formatter formatter = getFormatterFromString(formatters.get(i + 1));

actions.put(field, formatter);
try {
String field = formatters.get(i);
Formatter formatter = getFormatterFromString(formatters.get(i + 1));

actions.put(field, formatter);
} catch(IndexOutOfBoundsException e){
// the meta data string in the file is broken. -> Ignore the last item
break;
}
}

}
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/net/sf/jabref/exporter/SaveActionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ public void checkSaveActionsParsing() throws IOException {
assertEquals("Educational session 1", actedUpon.getField("title"));
}

@Test
public void invalidSaveActionSting() throws IOException {
BibtexParser parser = new BibtexParser(new StringReader("@InProceedings{6055279,\n" +
" Title = {Educational session 1},\n" +
" Booktitle = {Custom Integrated Circuits Conference (CICC), 2011 IEEE},\n" +
" Year = {2011},\n" +
" Month = {Sept},\n" +
" Pages = {1-7},\n" +
" Abstract = {Start of the above-titled section of the conference proceedings record.},\n" +
" DOI = {10.1109/CICC.2011.6055279},\n" +
" ISSN = {0886-5930}\n" +
"}\n" +
"\n" +
"@comment{jabref-meta: saveActions:title;}"));

ParserResult parserResult = parser.parse();

SaveActions actions = new SaveActions(parserResult.getMetaData());

BibEntry actedUpon = actions.applySaveActions(parserResult.getDatabase().getEntries().iterator().next());

assertEquals("Educational session 1", actedUpon.getField("title"));
}

@Test
public void checkLowerCaseSaveAction() throws IOException {
BibtexParser parser = new BibtexParser(new StringReader("@InProceedings{6055279,\n" +
Expand Down

0 comments on commit ae9e874

Please sign in to comment.