diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f77c603d8..61130cb9435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index bab25ab4aa7..ed7ff8aaf5c 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -263,8 +263,8 @@ public List performSearch(String query) throws FetcherException { @Override public Optional 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())); } @@ -372,17 +372,18 @@ public Optional getPdfUrl() { * Returns the arXiv identifier */ public Optional 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 getId() { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java index 4c3fd88b745..e988822af5a 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java @@ -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 ")); + } }