mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Improve validation for user.website
closes #4444 - validate URL without protocol in server and client - when saving url, add `http://` if the url doesn't have a protocol
This commit is contained in:
parent
f76088169a
commit
2e8e2ce367
2 changed files with 11 additions and 1 deletions
|
@ -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'});
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue