Skip to content

Commit 720fd8e

Browse files
authoredJul 31, 2021
Fix file field parser not recognizing online urls (#7948)
* Fix file field parser not recognizing online urls Fixes #7882 * checkstyle * fix test
1 parent 9f14196 commit 720fd8e

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
2323

2424
- 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)
2525
- 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)
26+
- 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)
2627

2728
### Removed
2829

‎src/main/java/org/jabref/logic/importer/util/FileFieldParser.java

+14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
import org.jabref.model.entry.LinkedFile;
1111

12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
1215
public class FileFieldParser {
16+
private static final Logger LOGGER = LoggerFactory.getLogger(FileFieldParser.class);
1317

1418
public static List<LinkedFile> parse(String value) {
1519
List<LinkedFile> files = new ArrayList<>();
@@ -18,6 +22,16 @@ public static List<LinkedFile> parse(String value) {
1822
return files;
1923
}
2024

25+
if (LinkedFile.isOnlineLink(value.trim())) {
26+
// needs to be modifiable
27+
try {
28+
return List.of(new LinkedFile(new URL(value), ""));
29+
} catch (MalformedURLException e) {
30+
LOGGER.error("invalid url", e);
31+
return files;
32+
}
33+
}
34+
2135
List<String> linkedFileData = new ArrayList<>();
2236
StringBuilder sb = new StringBuilder();
2337
boolean inXmlChar = false;

‎src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ private static Stream<Arguments> stringsToParseTestData() throws Exception {
136136
Arguments.of(
137137
Collections.singletonList(new LinkedFile("desc", Path.of("file.pdf"), "PDF")),
138138
"desc:file.pdf:PDF:asdf"
139+
),
140+
141+
// url
142+
Arguments.of(
143+
Collections.singletonList(new LinkedFile(new URL("https://books.google.de/"), "")),
144+
"https://books.google.de/"
145+
),
146+
147+
// url as file
148+
Arguments.of(
149+
Collections.singletonList(new LinkedFile("", new URL("http://ceur-ws.org/Vol-438"), "URL")),
150+
":http\\://ceur-ws.org/Vol-438:URL"
139151
)
140152
);
141153
}

0 commit comments

Comments
 (0)
Please sign in to comment.