Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file field parser not recognizing online urls #7948

Merged
merged 3 commits into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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