From 0d6117d585ffc7a7b04e841deeec26a65f5833a2 Mon Sep 17 00:00:00 2001 From: mathias4833 <67101597+mathias4833@users.noreply.github.com> Date: Sat, 29 Mar 2025 17:52:02 +0100 Subject: [PATCH] fix(gui): validate device ID in canonical form (fixes #7291) (#10006) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Purpose In the GUI, the device ID validation was case-sensitive and didn’t account for dash variations, which allowed users to enter an existing device ID without receiving proper feedback. This fix ensures the ID is validated in its canonical form, thus preventing the user from submitting the request if the device ID already exists. ### Testing To test this change, try adding a new device with an ID that matches an existing device, but with a different case or dashes. --- .../syncthing/core/validDeviceidDirective.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/gui/default/syncthing/core/validDeviceidDirective.js b/gui/default/syncthing/core/validDeviceidDirective.js index 0a84ffe06..71c231565 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; }); }