summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Frölich <40638719+tobifroe@users.noreply.github.com>2024-11-12 09:24:00 +0100
committerGitHub <noreply@github.com>2024-11-12 09:24:00 +0100
commit1a529e9d5d893abc0d99aba98b50cd3e60f233ca (patch)
tree46cc579c79c73874407db8c97b71978798a4131d
parent36ef17df8f95d0891f2e6e1cb87c93b7e7ba8fa3 (diff)
fix(gui): expand tildes for subdir check (fixes #9400) (#9788)
### Purpose This closes #9400 by always expanding tildes when parent/subdir checks are done. ### Testing I tested this by creating folders with paths to parent or subdirectories of the default folder that include a tilde in their path as shown in the attached screenshots. With this change, overlap will be detected regardless of wether or not tildes are used in other folder paths. ### Screenshots Default Folder: ![2024-10-26-At-08h40m33s](https://github.com/user-attachments/assets/07df090c-4481-41ec-b741-d2785fc848d5) Newly created folder (parent directory in this case) ![2024-10-26-At-08h40m13s](https://github.com/user-attachments/assets/636fa1fd-41dc-44d9-ac90-0a4937c9921c) --------- Signed-off-by: tobifroe <froeltob@pm.me>
-rw-r--r--gui/default/syncthing/core/pathIsSubDirDirective.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/gui/default/syncthing/core/pathIsSubDirDirective.js b/gui/default/syncthing/core/pathIsSubDirDirective.js
index 38674d91fd..e1535e5035 100644
--- a/gui/default/syncthing/core/pathIsSubDirDirective.js
+++ b/gui/default/syncthing/core/pathIsSubDirDirective.js
@@ -6,7 +6,12 @@ angular.module('syncthing.core')
ctrl.$validators.folderPathErrors = function (viewValue) {
// This function checks whether ydir is a subdirectory of xdir,
// e.g. it would return true if xdir = "/home/a", ydir = "/home/a/b".
+ // Tildes in both xdir and ydir are expanded for comparison
+ // so that e.g. xdir = "home/a/", ydir = "~/b" will return true.
function isSubDir(xdir, ydir) {
+ var tildeExpansionRegex = new RegExp(`^~${scope.system.pathSeparator}|^~/`);
+ xdir = xdir.replace(tildeExpansionRegex, `${scope.system.tilde}${scope.system.pathSeparator}`);
+ ydir = ydir.replace(tildeExpansionRegex, `${scope.system.tilde}${scope.system.pathSeparator}`);
var xdirArr = xdir.split(scope.system.pathSeparator);
var ydirArr = ydir.split(scope.system.pathSeparator);
if (xdirArr.slice(-1).pop() === "") {