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 pdf content importer exception if DOI is empty #7207

Merged
merged 2 commits into from
Dec 19, 2020
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 @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,17 @@ Optional<BibEntry> 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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,26 @@ void testParsingEditorWithoutPagesorSeriesInformation() {

assertEquals(Optional.of(entry), importer.getEntryFromPDFContent(firstPageContents, "\n"));
}

@Test
void testParsingWithoutActualDOINumber() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even with a test case. Thank you!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

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"));

}
}