From c3729874d5f5600fa64038367610888308185be4 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 31 Jul 2021 00:01:33 +0200 Subject: [PATCH 1/3] Fix file field parser not recognizing online urls Fixes #7882 --- CHANGELOG.md | 1 + .../logic/importer/util/FileFieldParser.java | 16 ++++++++++++++++ .../logic/importer/util/FileFieldParserTest.java | 12 ++++++++++++ 3 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd26fa03dce..7c2c449fe12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,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..aeefbe58dc4 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,12 @@ 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 +23,17 @@ 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..199b0700df4 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" ) ); } From 437a15ba3e9be9cda8870b16b954e86462c65a22 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 31 Jul 2021 00:05:21 +0200 Subject: [PATCH 2/3] checkstyle --- .../java/org/jabref/logic/importer/util/FileFieldParser.java | 2 -- 1 file changed, 2 deletions(-) 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 aeefbe58dc4..24a5c136fd5 100644 --- a/src/main/java/org/jabref/logic/importer/util/FileFieldParser.java +++ b/src/main/java/org/jabref/logic/importer/util/FileFieldParser.java @@ -15,7 +15,6 @@ public class FileFieldParser { private static final Logger LOGGER = LoggerFactory.getLogger(FileFieldParser.class); - public static List parse(String value) { List files = new ArrayList<>(); @@ -33,7 +32,6 @@ public static List parse(String value) { } } - List linkedFileData = new ArrayList<>(); StringBuilder sb = new StringBuilder(); boolean inXmlChar = false; From ab60048c8cac90504c63944d5bb2e117999cbd77 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 31 Jul 2021 00:15:51 +0200 Subject: [PATCH 3/3] fix test --- .../org/jabref/logic/importer/util/FileFieldParserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 199b0700df4..4ccf9a150b6 100644 --- a/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java +++ b/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java @@ -147,7 +147,7 @@ private static Stream stringsToParseTestData() throws Exception { // 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" + ":http\\://ceur-ws.org/Vol-438:URL" ) ); }