fix(image) add validation of image name in build image page [EE-3010] (#6988)

* EE-3010 add validation of image name
pull/7031/head
Chao Geng 2022-06-07 16:42:09 +08:00 committed by GitHub
parent 0864c371e8
commit eb547162e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -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) {

View File

@ -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 -->