2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Merge pull request #4466 from VictorVation/url-validation

Improve validation for user.website
This commit is contained in:
Hannah Wolfe 2014-11-17 15:43:25 +00:00
commit 1079ef8aeb
2 changed files with 11 additions and 1 deletions

View file

@ -51,7 +51,7 @@ var UserValidator = Ember.Object.create({
}
if (!Ember.isEmpty(website) &&
(!validator.isURL(website, {protocols: ['http', 'https'], require_protocol: true}) ||
(!validator.isURL(website, {require_protocol: false}) ||
!validator.isLength(website, 0, 2000))) {
validationErrors.push({message: 'Website is not a valid url'});
}

View file

@ -94,6 +94,16 @@ User = ghostBookshelf.Model.extend({
return attrs;
},
format: function (options) {
if (!_.isEmpty(options.website) &&
!validator.isURL(options.website, {
require_protocol: true,
protocols: ['http', 'https']})) {
options.website = 'http://' + options.website;
}
return options;
},
posts: function () {
return this.hasMany('Posts', 'created_by');
},