mirror of https://github.com/portainer/portainer
fix(image) add validation of image name in build image page [EE-3010] (#6988)
* EE-3010 add validation of image namepull/7031/head
parent
0864c371e8
commit
eb547162e9
|
@ -27,6 +27,13 @@ function BuildImageController($scope, $async, $window, ModalService, BuildServic
|
|||
$scope.state.isEditorDirty = false;
|
||||
});
|
||||
|
||||
$scope.checkName = function (name) {
|
||||
const parts = name.split('/');
|
||||
const repository = parts[parts.length - 1];
|
||||
const repositoryRegExp = RegExp('^[a-z0-9-_]{2,255}(:[A-Za-z0-9-_.]{1,128})?$');
|
||||
return repositoryRegExp.test(repository);
|
||||
};
|
||||
|
||||
$scope.addImageName = function () {
|
||||
$scope.formValues.ImageNames.push({ Name: '' });
|
||||
};
|
||||
|
@ -92,13 +99,16 @@ function BuildImageController($scope, $async, $window, ModalService, BuildServic
|
|||
}
|
||||
|
||||
$scope.validImageNames = function () {
|
||||
if ($scope.formValues.ImageNames.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < $scope.formValues.ImageNames.length; i++) {
|
||||
var item = $scope.formValues.ImageNames[i];
|
||||
if (item.Name !== '') {
|
||||
return true;
|
||||
if (!$scope.checkName(item.Name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
$scope.editorUpdate = function (cm) {
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<span class="input-group-addon">name</span>
|
||||
<input type="text" class="form-control" ng-model="item.Name" placeholder="e.g. my-image:my-tag" auto-focus />
|
||||
<span class="input-group-addon"
|
||||
><i ng-class="{ true: 'fa fa-check green-icon', false: 'fa fa-times red-icon' }[item.Name !== '']" aria-hidden="true"></i
|
||||
><i ng-class="{ true: 'fa fa-check green-icon', false: 'fa fa-times red-icon' }[checkName(item.Name)]" aria-hidden="true"></i
|
||||
></span>
|
||||
</div>
|
||||
<!-- !name-input -->
|
||||
|
|
Loading…
Reference in New Issue