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 attach file does not relativize file path #4252

Merged
merged 7 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where the preview pane in entry preview in preferences wasn't showing the citation style selected [#3849](https://github.com/JabRef/jabref/issues/3849)
- We fixed an issue where the default entry preview style still contained the field `review`. The field `review` in the style is now replaced with comment to be consistent with the entry editor [#4098](https://github.com/JabRef/jabref/issues/4098)
- We fixed an issue where users were vulnerable to XXE attacks during parsing [#4229](https://github.com/JabRef/jabref/issues/4229)
- We fixed an issue where files added via the "Attach file" contextmenu of an entry were not made relative. [#4201](https://github.com/JabRef/jabref/issues/4201)
- We fixed an issue where files added via the "Attach file" contextmenu of an entry were not made relative. [#4201](https://github.com/JabRef/jabref/issues/4201) and [#4241](https://github.com/JabRef/jabref/issues/4241)
- We fixed an issue where author list parser can't generate bibtex for Chinese author. [#4169](https://github.com/JabRef/jabref/issues/4169)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ public void openBrowseDialog() {
// Store the directory for next time:
preferences.setWorkingDir(path);

// If the file is below the file directory, make the path relative:
List<Path> fileDirectories = database.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());
path = FileUtil.shortenFileName(path, fileDirectories);

link.set(path.toString());
relativizeFile();

setExternalFileTypeByExtension(link.getValueSafe());
});
}
Expand All @@ -97,6 +95,8 @@ public void setValues(LinkedFile linkedFile) {
description.set(linkedFile.getDescription());
link.set(linkedFile.getLink());

relativizeFile();

selectedExternalFileType.setValue(null);

// See what is a reasonable selection for the type combobox:
Expand Down Expand Up @@ -128,4 +128,12 @@ public LinkedFile getNewLinkedFile() {
return new LinkedFile(description.getValue(), link.getValue(), monadicSelectedExternalFileType.map(ExternalFileType::toString).getOrElse(""));
}

private void relativizeFile() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, it is hard to tell from the outside on which path this methods operates. I would thus prefer if relativizeFile would accept a path and return the relativized path (probably also rename to relativize[Path]). Then in would look like link.set(relativize(path)).

Copy link
Member Author

@Siedlerchr Siedlerchr Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already had considered this option as well, but seem to have forgotten about it ;)

Path filePath = Paths.get(link.get());
List<Path> fileDirectories = database.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());
filePath = FileUtil.shortenFileName(filePath, fileDirectories);
link.set(filePath.toString());

}

}