diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ba8762b633..16a227eec57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where the context menu was not updated after a file link was changed. [#5777](https://github.com/JabRef/jabref/issues/5777) - We fixed an issue where the password for a shared SQL database was not remembered [#6869](https://github.com/JabRef/jabref/issues/6869) - We fixed an issue where newly added entires were not synced to a shared SQL database [#7176](https://github.com/JabRef/jabref/issues/7176) +- We fixed an issue where the PDF-Content importer threw an exception when no DOI number is present at the first page of the PDF document [#7203](https://github.com/JabRef/jabref/issues/7203) ### Removed diff --git a/src/main/java/org/jabref/logic/importer/fileformat/PdfContentImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/PdfContentImporter.java index 1a8a9a6e900..a9d62a59181 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/PdfContentImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/PdfContentImporter.java @@ -418,15 +418,17 @@ Optional getEntryFromPDFContent(String firstpageContents, String lineS } if (pos >= 0) { pos += 3; - char delimiter = curString.charAt(pos); - if ((delimiter == ':') || (delimiter == ' ')) { - pos++; - } - int nextSpace = curString.indexOf(' ', pos); - if (nextSpace > 0) { - DOI = curString.substring(pos, nextSpace); - } else { - DOI = curString.substring(pos); + if (curString.length() > pos) { + char delimiter = curString.charAt(pos); + if ((delimiter == ':') || (delimiter == ' ')) { + pos++; + } + int nextSpace = curString.indexOf(' ', pos); + if (nextSpace > 0) { + DOI = curString.substring(pos, nextSpace); + } else { + DOI = curString.substring(pos); + } } } } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTest.java index 2a8cacefe20..faf37949972 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTest.java @@ -88,4 +88,26 @@ void testParsingEditorWithoutPagesorSeriesInformation() { assertEquals(Optional.of(entry), importer.getEntryFromPDFContent(firstPageContents, "\n")); } + + @Test + void testParsingWithoutActualDOINumber() { + BibEntry entry = new BibEntry(StandardEntryType.InProceedings); + entry.withField(StandardField.AUTHOR, "Link to record in KAR and http://kar.kent.ac.uk/51043/ and Document Version and UNSPECIFIED and Master of Research (MRes) thesis and University of Kent") + .withField(StandardField.TITLE, "Kent Academic Repository Full text document (pdf) Citation for published version Smith, Lucy Anna (2014) Mortality in the Ornamental Fish Retail Sector: an Analysis of Stock Losses and Stakeholder Opinions. DOI") + .withField(StandardField.YEAR, "5104"); + + String firstPageContents = "Kent Academic Repository Full text document (pdf)\n" + + "Citation for published version\n" + + "Smith, Lucy Anna (2014) Mortality in the Ornamental Fish Retail Sector: an Analysis of Stock\n" + + "Losses and Stakeholder Opinions.\n" + + "DOI\n\n\n" + + "Link to record in KAR\n" + + "http://kar.kent.ac.uk/51043/\n" + + "Document Version\n" + + "UNSPECIFIED\n" + + "Master of Research (MRes) thesis, University of Kent,."; + + assertEquals(Optional.of(entry), importer.getEntryFromPDFContent(firstPageContents, "\n")); + + } }