From 720fd8e7bc77f7dac528a8af31e7e31bb4e09f53 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 31 Jul 2021 17:53:27 +0200 Subject: [PATCH] Fix file field parser not recognizing online urls (#7948) * Fix file field parser not recognizing online urls Fixes #7882 * checkstyle * fix test --- CHANGELOG.md | 1 + .../logic/importer/util/FileFieldParser.java | 14 ++++++++++++++ .../logic/importer/util/FileFieldParserTest.java | 12 ++++++++++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19306a00169..0a8c034a42a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue when checking for a new version when JabRef is used behind a corporate proxy. [#7884](https://github.com/JabRef/jabref/issues/7884) - We fixed an issue where it was impossible to add or modify groups. [#7912](https://github.com/JabRef/jabref/pull/793://github.com/JabRef/jabref/pull/7921) +- We fixed an issue where exported entries from a Citavi bib containing URLs could not be imported [#7892](https://github.com/JabRef/jabref/issues/7882) ### Removed diff --git a/src/main/java/org/jabref/logic/importer/util/FileFieldParser.java b/src/main/java/org/jabref/logic/importer/util/FileFieldParser.java index 02632488eed..24a5c136fd5 100644 --- a/src/main/java/org/jabref/logic/importer/util/FileFieldParser.java +++ b/src/main/java/org/jabref/logic/importer/util/FileFieldParser.java @@ -9,7 +9,11 @@ import org.jabref.model.entry.LinkedFile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class FileFieldParser { + private static final Logger LOGGER = LoggerFactory.getLogger(FileFieldParser.class); public static List parse(String value) { List files = new ArrayList<>(); @@ -18,6 +22,16 @@ public static List parse(String value) { return files; } + if (LinkedFile.isOnlineLink(value.trim())) { + // needs to be modifiable + try { + return List.of(new LinkedFile(new URL(value), "")); + } catch (MalformedURLException e) { + LOGGER.error("invalid url", e); + return files; + } + } + List linkedFileData = new ArrayList<>(); StringBuilder sb = new StringBuilder(); boolean inXmlChar = false; diff --git a/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java b/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java index 11c74196d5c..4ccf9a150b6 100644 --- a/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java +++ b/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java @@ -136,6 +136,18 @@ private static Stream stringsToParseTestData() throws Exception { Arguments.of( Collections.singletonList(new LinkedFile("desc", Path.of("file.pdf"), "PDF")), "desc:file.pdf:PDF:asdf" + ), + + // url + Arguments.of( + Collections.singletonList(new LinkedFile(new URL("https://books.google.de/"), "")), + "https://books.google.de/" + ), + + // url as file + Arguments.of( + Collections.singletonList(new LinkedFile("", new URL("http://ceur-ws.org/Vol-438"), "URL")), + ":http\\://ceur-ws.org/Vol-438:URL" ) ); }