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 handling of URL in file field #7347

Merged
merged 8 commits into from
Jan 24, 2021
13 changes: 12 additions & 1 deletion src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.jabref.logic.importer.util.FileFieldParser;
import org.jabref.logic.util.OS;
import org.jabref.model.entry.LinkedFile;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class FileFieldWriterTest {

Expand Down Expand Up @@ -47,8 +50,16 @@ public void parseCorrectOnlineInput() throws MalformedURLException {
public void parseFaultyOnlineInput() {
String input = ":htt\\://arxiv.org/pdf/2010.08497v1:PDF";
String inputURL = "htt://arxiv.org/pdf/2010.08497v1";
List<LinkedFile> expected = Collections.singletonList(new LinkedFile("", Path.of(inputURL), "PDF"));

if (OS.WINDOWS) {
// on Windows, a ":" in a path cannot be used
// java.nio.file.InvalidPathException: Illegal char <:> at index 3: htt://arxiv.org/pdf/2010.08497v1
// Thus, we assert that statement and return
assertThrows(InvalidPathException.class, () -> Path.of(inputURL));
return;
}

List<LinkedFile> expected = Collections.singletonList(new LinkedFile("", Path.of(inputURL), "PDF"));
koppor marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(expected, FileFieldParser.parse(input));
}

Expand Down