Repository: syncthing/syncthing (language: go)

Issue:
GUI check for own/already-existing device ID could be better
### Does your log mention database corruption?
Not yet ;-)
Also, the new device won't show in devices list


Discussion / hints:
Ooops : <confused>I added my own ID !!!! </confused>
It seems the check to see if device already exists doesn't check our own ID.... 
If I understand correctly, you mean that you have added your own ID as a remote device. Is this correct? Can you describe exactly how you did it?

The GUI does not allow doing so normally. This is what one gets when trying to add their own ID.

![image](https://user-images.githubusercontent.com/5626656/105141812-0f22be80-5b3d-11eb-9118-57307fd42f64.png)

I can reproduce. While trying I noticed that typing the ID lower-case and no dashes, or at least e.g. the last character, the pre-existence test doesn't work, and validating doesn't change our "Device Name" anymore.
But I also noticed that the test is not reliable : e.g. swapping 2 letters in the end past the 52 first won't show the warning. I also noticed some months ago that weird thing happen between 52 and 56th chars. At least the dashes should be stripped out and entries should be case-insensitive while checking if not yet. In my memory I said to myself there was a difficulty here because valid ID may be either 52 or 56 chars in length. Please confirm.

Corner~case~ ;-) reproduce : Add new device-> enter our ID so that warning won't trigger before validating (eg, replace latest letter to lower-case  -> Enter a "Device Name" that ALREADY exists in your list (I only did this with exact same case) -> Validate -> Our "Device Name" is changed accordingly.
Strangely, doing a second shoot (to revert back or even try with another existing Device Name) won't "work" until I changed back my Device Name from Action/Settings
Sounds like the already-exists-check doesn't take all possible variations of the device ID into account. It should resolve it to canonical form before checking.
> Sounds like the already-exists-check doesn't take all possible variations of the device ID into account. It should resolve it to canonical form before checking.

Yes Jakob. Furthermore, ST quits on restart: I got rid of that by cleaning the dup in config.xml
```
[start] 10:21:58 INFO: syncthing v1.13.0-rc.1 "Fermium Flea" (go1.15.6 windows-amd64) teamcity@build.syncthing.net 2021-01-11 14:15:21 UTC
[start] 10:21:58 INFO: Automatic upgrade is always enabled for candidate releases.
[334ZK] 10:21:58 INFO: My ID: 334YZDC-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-3K3FFAU
[334ZK] 10:21:59 INFO: Single thread SHA256 performance is 466 MB/s using minio/sha256-simd (402 MB/s using crypto/sha256).
[334YZ] 10:21:59 WARNING: Short device IDs are in conflict. Unlucky!
  Regenerate the device ID of one of the following:
   334YZDC-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-3K3FFQE in conflict with 334YZDC-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-3K3FFAU
[334ZK] 10:22:00 INFO: Exiting
```
Notice how the 2 strings differ on the last 2 chars
That's not a dup though, that's just that you added a device ID you made up that's almost identical to another device ID, and Syncthing can't handle if they don't differ somewhere in the first 64 bits.

Fix patch:
diff --git a/gui/default/syncthing/core/validDeviceidDirective.js b/gui/default/syncthing/core/validDeviceidDirective.js
index 0a84ffe06af..71c231565cf 100644
--- a/gui/default/syncthing/core/validDeviceidDirective.js
+++ b/gui/default/syncthing/core/validDeviceidDirective.js
@@ -5,18 +5,12 @@ angular.module('syncthing.core')
             link: function (scope, elm, attrs, ctrl) {
                 ctrl.$parsers.unshift(function (viewValue) {
                     $http.get(urlbase + '/svc/deviceid?id=' + viewValue).success(function (resp) {
-                        if (resp.error) {
-                            ctrl.$setValidity('validDeviceid', false);
-                        } else {
-                            ctrl.$setValidity('validDeviceid', true);
-                        }
+                        let isValid = !resp.error;
+                        let isUnique = !isValid || !scope.devices.hasOwnProperty(resp.id);
+
+                        ctrl.$setValidity('validDeviceid', isValid);
+                        ctrl.$setValidity('unique', isUnique);
                     });
-                    //Prevents user from adding a duplicate ID
-                    if (scope.devices.hasOwnProperty(viewValue)) {
-                        ctrl.$setValidity('unique', false);
-                    } else {
-                        ctrl.$setValidity('unique', true);
-                    }
                     return viewValue;
                 });
             }


Test patch: