Skip to content

Commit

Permalink
Fixes #4544 Do not extract file ending from Urls
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Dec 21, 2018
1 parent 949d204 commit 725ce6a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/org/jabref/model/util/FileHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.model.util;

import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -31,6 +32,10 @@ public static Optional<String> getFileExtension(Path file) {
* @return The extension (without leading dot), trimmed and in lowercase.
*/
public static Optional<String> getFileExtension(String fileName) {
if (isUrl(fileName)) {
return Optional.empty();
}

int dotPosition = fileName.lastIndexOf('.');
if ((dotPosition > 0) && (dotPosition < (fileName.length() - 1))) {
return Optional.of(fileName.substring(dotPosition + 1).trim().toLowerCase(Locale.ROOT));
Expand Down Expand Up @@ -129,4 +134,13 @@ private static Optional<Path> expandFilename(String filename, Path directory) {
return Optional.empty();
}
}

private static boolean isUrl(String url) {

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr Dec 22, 2018

Member

Looks more like a hack, but apparently there is no better solutiohn

try {
new URL(url);
return true;
} catch (Exception e) {
return false;
}
}
}

0 comments on commit 725ce6a

Please sign in to comment.