Skip to content

Commit

Permalink
Fix file field parser not recognizing online urls
Browse files Browse the repository at this point in the history
Fixes #7882
  • Loading branch information
Siedlerchr committed Jul 30, 2021
1 parent 2bec2a8 commit c372987
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 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,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<LinkedFile> parse(String value) {
List<LinkedFile> files = new ArrayList<>();
Expand All @@ -18,6 +23,17 @@ 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 c372987

Please sign in to comment.