Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Improve URL validation on setup flow #1320

Merged
merged 1 commit into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions components/app-core/frontend/src/utils/utils.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@
'$', 'i'
);

var localUrlValidationExpression = new RegExp(
'^' +
// protocol identifier
'http(s)?://' +
// user:pass authentication
'(?:\\S+(?::\\S*)?@)?' +
// host name
'(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)' +
// port number
'(?::\\d{2,5})?' +
// resource path
'(?:[/?#]\\S*)?' +
'$', 'i'
);

var colorCodes = {
black: 0,
red: 1,
Expand All @@ -88,6 +103,7 @@
runInSequence: runInSequence,
sizeUtilization: sizeUtilization,
urlValidationExpression: urlValidationExpression,
localUrlValidationExpression: localUrlValidationExpression,
extractCloudFoundryError: extractCloudFoundryError,
extractCodeEngineError: extractCodeEngineError,
coloredLog: coloredLog,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(function () {
'use strict';

angular
.module('app.view')
.directive('stratosUrl', stratosUrl);

function stratosUrl(appUtilsService) {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, elm, attr, ctrl) {
if (!ctrl) {
return;
}
ctrl.$validators.pattern = function (modelValue, viewValue) {
return ctrl.$isEmpty(viewValue) || appUtilsService.urlValidationExpression.test(viewValue) || appUtilsService.localUrlValidationExpression.test(viewValue);
};
}
};
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
name="uaaUrl"
ng-model="step.userInput.uaaUrl"
required
stratos-url
placeholder="{{'app-setup.step-1.uaa-url.placeholder' | translate}}"/>
</div>
<div class="form-group form-group-large skip-ssl-validation-checkbox" focusable-input>
Expand Down