Skip to content

Commit

Permalink
Do not check external file links
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Jan 22, 2016
1 parent cab451a commit 5cf5329
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/FileListTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ else if (!escaped && (c == ':')) {
return files;
}

public FileListEntry setContent(String value, boolean firstOnly, boolean deduceUnknownTypes) {
private FileListEntry setContent(String value, boolean firstOnly, boolean deduceUnknownTypes) {
if (value == null) {
value = "";
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/net/sf/jabref/importer/DatabaseFileLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,16 @@ public boolean lookupDatabase(File file) {
private List<File> parseFileField(BibEntry entry) {
Objects.requireNonNull(entry);

FileListTableModel model = new FileListTableModel();

String fileField = entry.getField(DatabaseFileLookup.KEY_FILE_FIELD);
model.setContent(fileField);
List<FileListEntry> entries = new FileListTableModel().parseFileField(fileField);

List<File> fileLinks = new ArrayList<>();
for (FileListEntry e : model.parseFileField(fileField)) {
for (FileListEntry e : entries) {
String link = e.getLink();

if (link == null) {
break;
// Do not query external file links (huge performance leak)
if(link == null || link.contains("//")) {
continue;
}

File expandedFilename = FileUtil.expandFilename(link, possibleFilePaths);
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/net/sf/jabref/logic/util/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class FileUtil {
private static final Log LOGGER = LogFactory.getLog(FileUtil.class);

private static final String FILE_SEPARATOR = System.getProperty("file.separator");

private static final Pattern SLASH = Pattern.compile("/");
private static final Pattern BACKSLASH = Pattern.compile("\\\\");

/**
* Returns the extension of a file or Optional.empty() if the file does not have one (no . in name).
Expand Down Expand Up @@ -181,14 +182,14 @@ public static boolean renameFile(String fileName, String destFilename) {
public static File expandFilename(final MetaData metaData, String name) {
Optional<String> extension = getFileExtension(name);
// Find the default directory for this field type, if any:
String[] dir = metaData.getFileDirectory(extension.orElse(null));
String[] directories = metaData.getFileDirectory(extension.orElse(null));
// Include the standard "file" directory:
String[] fileDir = metaData.getFileDirectory(Globals.FILE_FIELD);
// Include the directory of the bib file:
ArrayList<String> al = new ArrayList<>();
for (String aDir : dir) {
if (!al.contains(aDir)) {
al.add(aDir);
for (String dir : directories) {
if (!al.contains(dir)) {
al.add(dir);
}
}
for (String aFileDir : fileDir) {
Expand All @@ -207,11 +208,10 @@ public static File expandFilename(final MetaData metaData, String name) {
* Will look in each of the given dirs starting from the beginning and
* returning the first found file to match if any.
*/
public static File expandFilename(String name, String[] dir) {

for (String aDir : dir) {
if (aDir != null) {
File result = expandFilename(name, aDir);
public static File expandFilename(String name, String[] directories) {
for (String dir : directories) {
if (dir != null) {
File result = expandFilename(name, dir);
if (result != null) {
return result;
}
Expand All @@ -226,30 +226,29 @@ public static File expandFilename(String name, String[] dir) {
* null if the file does not exist.
*/
public static File expandFilename(String name, String dir) {

if ((name == null) || name.isEmpty()) {
return null;
}

File file = new File(name);

if (!file.exists() && (dir != null)) {
if (dir.endsWith(FILE_SEPARATOR)) {
name = dir + name;
} else {
name = dir + FILE_SEPARATOR + name;
}

file = new File(name);

if (file.exists()) {
return file;
}
// fix / and \ problems:
if (OS.WINDOWS) {
name = name.replaceAll("/", "\\\\");
name = SLASH.matcher(name).replaceAll("\\\\");
} else {
name = name.replaceAll("\\\\", "/");
name = BACKSLASH.matcher(name).replaceAll("/");
}

file = new File(name);

if (!file.exists()) {
file = null;
}
Expand Down

0 comments on commit 5cf5329

Please sign in to comment.