From 381f6aeaf6889f83e02a3e02fe08e7414e62d83a Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 28 May 2014 05:16:11 +0200 Subject: [PATCH] Handle and prevent invalid repo ID. Validate node ID format. (fixes #286) --- gui/app.js | 28 ++++++++++++++++++++++++++++ gui/index.html | 14 ++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/gui/app.js b/gui/app.js index ba046244a..8029f30b6 100644 --- a/gui/app.js +++ b/gui/app.js @@ -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; + }); + } + }; +}); diff --git a/gui/index.html b/gui/index.html index 057e1615e..a75f67656 100644 --- a/gui/index.html +++ b/gui/index.html @@ -125,13 +125,13 @@
-
+
@@ -195,10 +195,10 @@
@@ -415,13 +415,14 @@
- +
{{currentNode.NodeID | chunkID}}

The node ID to enter here can be found in the "Edit > Show ID" dialog on the other node. Spaces and dashes are optional (ignored). When adding a new node, keep in mind that this node must be added on the other side too. The node ID cannot be blank. + The entered node ID does not look valid. It should be a 52 character string consisting of letters and numbers, with spaces and dashes being optional.

@@ -460,11 +461,12 @@
- +

Short identifier for the repository. Must be the same on all cluster nodes. The repository ID must be unique. The repository ID cannot be blank. + The repository ID must be a short identifier (64 characters or less) consisting of letters, numbers and the the -_. characters only.