From eb988b6ead6beae3d64b95aa8827567adf8b81df Mon Sep 17 00:00:00 2001 From: systemoperator Date: Wed, 29 Jan 2020 13:18:21 +0100 Subject: [PATCH 1/2] Fixes making paths of linked files relative (web urls will not be touched anymore) (#5879) * Fixes #5861 Description: - Cleanup entries: "Make paths of linked files relative (if possible)" broke web URLs and resulted in various other issues subsequently. This PR fixes this issue. It has been tested for local files and web urls. * changelog updated * refactoring: use existing method isOnlineLink() for checking whether a file link is an online link; improving isOnlineLink() --- CHANGELOG.md | 1 + .../logic/cleanup/RelativePathsCleanup.java | 16 +++++++++++----- .../java/org/jabref/model/entry/LinkedFile.java | 5 +++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aacb7819b24..6ffa4e88747 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where the ampersand character wasn't rendering correctly on previews. [#3840](https://github.com/JabRef/jabref/issues/3840) - We fixed an issue where an erroneous "The library has been modified by another program" message was shown when saving. [#4877](https://github.com/JabRef/jabref/issues/4877) - We fixed an issue where the file extension was missing after downloading a file (we now fall-back to pdf). [#5816](https://github.com/JabRef/jabref/issues/5816) +- We fixed an issue where cleaning up entries broke web URLs, if "Make paths of linked files relative (if possible)" was enabled, which resulted in various other issues subsequently. [#5861](https://github.com/JabRef/jabref/issues/5861) ### Removed - Ampersands are no longer escaped by default in the `bib` file. If you want to keep the current behaviour, you can use the new "Escape Ampersands" formatter as a save action. diff --git a/src/main/java/org/jabref/logic/cleanup/RelativePathsCleanup.java b/src/main/java/org/jabref/logic/cleanup/RelativePathsCleanup.java index 9b18e939782..1bbecb2f41c 100644 --- a/src/main/java/org/jabref/logic/cleanup/RelativePathsCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/RelativePathsCleanup.java @@ -33,10 +33,17 @@ public List cleanup(BibEntry entry) { for (LinkedFile fileEntry : fileList) { String oldFileName = fileEntry.getLink(); - String newFileName = FileUtil - .relativize(Paths.get(oldFileName), databaseContext.getFileDirectoriesAsPaths(filePreferences)) - .toString(); - + String newFileName = null; + if (fileEntry.isOnlineLink()) { + // keep online link untouched + newFileName = oldFileName; + } + else { + // only try to transform local file path to relative one + newFileName = FileUtil + .relativize(Paths.get(oldFileName), databaseContext.getFileDirectoriesAsPaths(filePreferences)) + .toString(); + } LinkedFile newFileEntry = fileEntry; if (!oldFileName.equals(newFileName)) { newFileEntry = new LinkedFile(fileEntry.getDescription(), newFileName, fileEntry.getFileType()); @@ -56,5 +63,4 @@ public List cleanup(BibEntry entry) { return Collections.emptyList(); } - } diff --git a/src/main/java/org/jabref/model/entry/LinkedFile.java b/src/main/java/org/jabref/model/entry/LinkedFile.java index 62a71dac417..3c79ffd6812 100644 --- a/src/main/java/org/jabref/model/entry/LinkedFile.java +++ b/src/main/java/org/jabref/model/entry/LinkedFile.java @@ -135,10 +135,11 @@ private void readObject(ObjectInputStream in) throws IOException { /** * Checks if the given String is an online link * @param toCheck The String to check - * @return True if it starts with http://, https:// or contains www; false otherwise + * @return true, if it starts with "http://", "https://" or contains "www."; false otherwise */ private boolean isOnlineLink(String toCheck) { - return toCheck.startsWith("http://") || toCheck.startsWith("https://") || toCheck.contains("www."); + String normalizedFilePath = toCheck.trim().toLowerCase(); + return normalizedFilePath.startsWith("http://") || normalizedFilePath.startsWith("https://") || normalizedFilePath.contains("www."); } @Override From f53568b0f370ffbe338b9fc9948892300e411c30 Mon Sep 17 00:00:00 2001 From: "Thomas F. Duellmann" Date: Wed, 29 Jan 2020 17:36:15 +0000 Subject: [PATCH 2/2] Replace link to Workspace set-up with new one (#5896) As the current link just pointed to a page with another link, I'd propose to directly put that second link. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff5ab937253..55c60c049a3 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ We view pull requests as a collaborative process. Submit a pull request early to get feedback from the team on work in progress. We will discuss improvements with you and agree to merge them once the [developers](https://github.com/JabRef/jabref/blob/master/DEVELOPERS) approve. -If you want a step-by-step walk-through on how to set-up your workspace, please check [this guideline](https://github.com/JabRef/jabref/wiki/Guidelines-for-setting-up-a-local-workspace). +If you want a step-by-step walk-through on how to set-up your workspace, please check [this guideline](https://devdocs.jabref.org/guidelines-for-setting-up-a-local-workspace/). To compile JabRef from source, you need a Java Development Kit 13 and `JAVA_HOME` pointing to this JDK. To run it, just execute `gradlew run`.