Repository: syncthing/syncthing (language: go)

Issue:
Folder overlap not detected when using tilde
### Steps to reproduce
1. After setup, the default folder should be at `/home/<username>/Sync`. Click 'Add Folder' and enter `~/Sync` or `~/Sync/a` for the folder path.
### Expected behavior
Following text should be shown:
> Warning, this path is a subdirectory of an existing folder "Default Folder" (default).
### Actual behavior
No warning is shown.
### System information
Syncthing v1.27.3-rc.2 on Ubuntu 22
### Further comments
I believe it would also be helpful to 1) require checking a box to confirm "I understand the implications" and 2) show the warning in the folder list as well.
Related issue would be detecting overlaps that are caused by symlinks.
As far as I can tell, [overlap detection is currently happening on the frontend](https://github.com/syncthing/syncthing/blob/main/gui/default/syncthing/core/pathIsSubDirDirective.js).
Folder overlap not detected when using tilde
### Steps to reproduce
1. After setup, the default folder should be at `/home/<username>/Sync`. Click 'Add Folder' and enter `~/Sync` or `~/Sync/a` for the folder path.
### Expected behavior
Following text should be shown:
> Warning, this path is a subdirectory of an existing folder "Default Folder" (default).
### Actual behavior
No warning is shown.
### System information
Syncthing v1.27.3-rc.2 on Ubuntu 22
### Further comments
I believe it would also be helpful to 1) require checking a box to confirm "I understand the implications" and 2) show the warning in the folder list as well.
Related issue would be detecting overlaps that are caused by symlinks.
As far as I can tell, [overlap detection is currently happening on the frontend](https://github.com/syncthing/syncthing/blob/main/gui/default/syncthing/core/pathIsSubDirDirective.js).


Discussion / hints:

Fix patch:
diff --git a/gui/default/syncthing/core/pathIsSubDirDirective.js b/gui/default/syncthing/core/pathIsSubDirDirective.js
index 38674d91fd5..e1535e5035b 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() === "") {


Test patch: