Skip to content

Commit c372987

Browse files
committed
Fix file field parser not recognizing online urls
Fixes #7882
1 parent 2bec2a8 commit c372987

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

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

2323
- 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)
2424
- 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)
25+
- 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)
2526

2627
### Removed
2728

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

+16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
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);
17+
1318

1419
public static List<LinkedFile> parse(String value) {
1520
List<LinkedFile> files = new ArrayList<>();
@@ -18,6 +23,17 @@ public static List<LinkedFile> parse(String value) {
1823
return files;
1924
}
2025

26+
if (LinkedFile.isOnlineLink(value.trim())) {
27+
// needs to be modifiable
28+
try {
29+
return List.of(new LinkedFile(new URL(value), ""));
30+
} catch (MalformedURLException e) {
31+
LOGGER.error("invalid url", e);
32+
return files;
33+
}
34+
}
35+
36+
2137
List<String> linkedFileData = new ArrayList<>();
2238
StringBuilder sb = new StringBuilder();
2339
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)