Skip to content

Commit

Permalink
ArXiv fetcher support http url (#4367)
Browse files Browse the repository at this point in the history
* ArXiv fetcher support http url

* add changelog entry and add some tests for the arxiv fether

* Keep comment
  • Loading branch information
zesaro authored and tobiasdiez committed Oct 10, 2018
1 parent d8d3807 commit 0a55a82
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where files added via the "Attach file" contextmenu of an entry were not made relative. [#4201](https://github.com/JabRef/jabref/issues/4201) and [#4241](https://github.com/JabRef/jabref/issues/4241)
- We fixed an issue where author list parser can't generate bibtex for Chinese author. [#4169](https://github.com/JabRef/jabref/issues/4169)
- We fixed an issue where the list of XMP Exclusion fields in the preferences was not be saved [#4072](https://github.com/JabRef/jabref/issues/4072)
- We fixed an issue where the ArXiv Fetcher did not support HTTP URLs [#4367](https://github.com/JabRef/jabref/pull/4367)



Expand Down
17 changes: 9 additions & 8 deletions src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ public List<BibEntry> performSearch(String query) throws FetcherException {

@Override
public Optional<BibEntry> performSearchById(String identifier) throws FetcherException {
String cleanedIdentifier = identifier.trim();
cleanedIdentifier = identifier.replaceAll(" ", "");
String cleanedIdentifier = identifier.replaceAll(" ", "");
cleanedIdentifier = ArXivEntry.createIdString(cleanedIdentifier);

return searchForEntryById(cleanedIdentifier).map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator()));
}
Expand Down Expand Up @@ -372,17 +372,18 @@ public Optional<URL> getPdfUrl() {
* Returns the arXiv identifier
*/
public Optional<String> getIdString() {
return urlAbstractPage.map(ArXivEntry::createIdString);
}

return urlAbstractPage.map(abstractUrl -> {
Matcher matcher = URL_PATTERN.matcher(abstractUrl);
public static String createIdString(String id) {
Matcher matcher = URL_PATTERN.matcher(id);
if (matcher.find()) {
// remove leading http(s)://arxiv.org/abs/ from abstract url to get arXiv ID
return abstractUrl.substring(matcher.group(1).length());
// Remove leading http(s)://arxiv.org/abs/ from abstract url to get arXiv ID
return id.substring(matcher.group(1).length());
} else {
return abstractUrl;
return id;
}

});
}

public Optional<ArXivIdentifier> getId() {
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,24 @@ public void searchIdentifierForSlicePaper() throws Exception {

assertEquals(ArXivIdentifier.parse("1405.2249v1"), finder.findIdentifier(sliceTheoremPaper));
}

@Test
public void searchEmptyId() throws Exception {
assertEquals(Optional.empty(), finder.performSearchById(""));
}

@Test
public void searchWithHttpUrl() throws Exception{
assertEquals(Optional.of(sliceTheoremPaper), finder.performSearchById("http://arxiv.org/abs/1405.2249"));
}

@Test
public void searchWithHttpsUrl() throws Exception{
assertEquals(Optional.of(sliceTheoremPaper), finder.performSearchById("https://arxiv.org/abs/1405.2249"));
}

@Test
public void searchWithHttpsUrlNotTrimmed() throws Exception{
assertEquals(Optional.of(sliceTheoremPaper), finder.performSearchById("https : // arxiv . org / abs / 1405 . 2249 "));
}
}

0 comments on commit 0a55a82

Please sign in to comment.