Skip to content

Commit 725ce6a

Browse files
committed
Fixes #4544 Do not extract file ending from Urls
1 parent 949d204 commit 725ce6a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/jabref/model/util/FileHelper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jabref.model.util;
22

3+
import java.net.URL;
34
import java.nio.file.Files;
45
import java.nio.file.Path;
56
import java.nio.file.Paths;
@@ -31,6 +32,10 @@ public static Optional<String> getFileExtension(Path file) {
3132
* @return The extension (without leading dot), trimmed and in lowercase.
3233
*/
3334
public static Optional<String> getFileExtension(String fileName) {
35+
if (isUrl(fileName)) {
36+
return Optional.empty();
37+
}
38+
3439
int dotPosition = fileName.lastIndexOf('.');
3540
if ((dotPosition > 0) && (dotPosition < (fileName.length() - 1))) {
3641
return Optional.of(fileName.substring(dotPosition + 1).trim().toLowerCase(Locale.ROOT));
@@ -129,4 +134,13 @@ private static Optional<Path> expandFilename(String filename, Path directory) {
129134
return Optional.empty();
130135
}
131136
}
137+
138+
private static boolean isUrl(String url) {
139+
try {
140+
new URL(url);
141+
return true;
142+
} catch (Exception e) {
143+
return false;
144+
}
145+
}
132146
}

0 commit comments

Comments
 (0)