Handle and prevent invalid repo ID. Validate node ID format. (fixes #286)

This commit is contained in:
Jakob Borg
2014-05-28 05:16:11 +02:00
parent 9154bacced
commit 381f6aeaf6
2 changed files with 36 additions and 6 deletions

View File

@@ -648,6 +648,12 @@ syncthing.filter('shortPath', function () {
}
});
syncthing.filter('clean', function () {
return function (input) {
return encodeURIComponent(input).replace(/%/g, '');
}
});
syncthing.directive('optionEditor', function () {
return {
restrict: 'C',
@@ -680,3 +686,25 @@ syncthing.directive('uniqueRepo', function() {
}
};
});
syncthing.directive('validNodeid', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift(function(viewValue) {
if (scope.editingExisting) {
// we shouldn't validate
ctrl.$setValidity('validNodeid', true);
} else {
var cleaned = viewValue.replace(/ /g, '').replace(/-/g, '').toUpperCase().trim();
if (cleaned.match(/^[A-Z2-7]{52}$/)) {
ctrl.$setValidity('validNodeid', true);
} else {
ctrl.$setValidity('validNodeid', false);
}
}
return viewValue;
});
}
};
});