gui: Fix folder path validation (fixes #7379) (#7585)

This commit is contained in:
Simon Frei 2021-04-20 17:29:06 +02:00 committed by GitHub
parent e4c995a321
commit 031b91c0ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -3,7 +3,7 @@ angular.module('syncthing.core')
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift(function (viewValue) {
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".
function isSubDir(xdir, ydir) {
@ -25,6 +25,9 @@ angular.module('syncthing.core')
scope.folderPathErrors.otherID = "";
scope.folderPathErrors.otherLabel = "";
for (var folderID in scope.folders) {
if (folderID === scope.currentFolder.id) {
continue;
}
if (isSubDir(scope.folders[folderID].path, viewValue)) {
scope.folderPathErrors.otherID = folderID;
scope.folderPathErrors.otherLabel = scope.folders[folderID].label;
@ -39,8 +42,8 @@ angular.module('syncthing.core')
break;
}
}
return viewValue;
});
return true;
};
}
};
});