Skip to content

Commit

Permalink
Fix file field parser not recognizing online urls (#7948)
Browse files Browse the repository at this point in the history
* Fix file field parser not recognizing online urls

Fixes #7882

* checkstyle

* fix test
  • Loading branch information
Siedlerchr authored Jul 31, 2021
1 parent 9f14196 commit 720fd8e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/jabref/logic/importer/util/FileFieldParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<LinkedFile> parse(String value) {
List<LinkedFile> files = new ArrayList<>();
Expand All @@ -18,6 +22,16 @@ public static List<LinkedFile> 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<String> linkedFileData = new ArrayList<>();
StringBuilder sb = new StringBuilder();
boolean inXmlChar = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ private static Stream<Arguments> 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"
)
);
}
Expand Down

0 comments on commit 720fd8e

Please sign in to comment.