From 0ef37d88ed2139873ad9a204c673dc3548fbbb64 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sat, 17 Oct 2020 17:41:14 +0200 Subject: [PATCH] remove any newlines and spaces in isbn when fetching (#7023) * remove any newlines and spaces in isbn when fetching Fixes #6456 * Update IsbnFetcher.java * Update CHANGELOG.md * remove duplicate changelog entry --- CHANGELOG.md | 1 + .../java/org/jabref/logic/importer/fetcher/IsbnFetcher.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45413f5a08e..5c26f8942fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ inserting new citations in a OpenOffic/LibreOffice document. [#6957](https://git - We fixed an issue where a remove icon was shown for standard entry types in the custom entry types dialog. [#6906](https://github.com/JabRef/jabref/issues/6906) - We fixed an issue where it was impossible to connect to OpenOffice/LibreOffice on Mac OSX. [#6970](https://github.com/JabRef/jabref/pull/6970) - We fixed an issue with the python script used by browser plugins that failed to locate JabRef if not installed in its default location. [#6963](https://github.com/JabRef/jabref/pull/6963/files) +- We fixed an issue where spaces and newlines in an isbn would generate an exception. [#6456](https://github.com/JabRef/jabref/issues/6456) - We fixed an issue where identity column header had incorrect foreground color in the Dark theme. [#6796](https://github.com/JabRef/jabref/issues/6796) - We fixed an issue where clicking on Collapse All button in the Search for Unlinked Local Files expanded the directory structure erroneously [#6848](https://github.com/JabRef/jabref/issues/6848) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java index eda85988ff6..626ae6a1edb 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.regex.Pattern; import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.EntryBasedFetcher; @@ -23,6 +24,7 @@ public class IsbnFetcher implements EntryBasedFetcher, IdBasedFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(IsbnFetcher.class); + private static final Pattern NEWLINE_SPACE_PATTERN = Pattern.compile("\\n|\\r\\n|\\s"); protected final ImportFormatPreferences importFormatPreferences; public IsbnFetcher(ImportFormatPreferences importFormatPreferences) { @@ -44,6 +46,8 @@ public Optional performSearchById(String identifier) throws FetcherExc if (StringUtil.isBlank(identifier)) { return Optional.empty(); } + // remove any newlines and spaces. + identifier = NEWLINE_SPACE_PATTERN.matcher(identifier).replaceAll(""); IsbnViaEbookDeFetcher isbnViaEbookDeFetcher = new IsbnViaEbookDeFetcher(importFormatPreferences); Optional bibEntry = isbnViaEbookDeFetcher.performSearchById(identifier);