From 2e8e2ce3677011bd497eddf203314e3a82604369 Mon Sep 17 00:00:00 2001 From: Victor Szeto Date: Sun, 16 Nov 2014 23:35:32 -0500 Subject: [PATCH] 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 --- core/client/validators/user.js | 2 +- core/server/models/user.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/client/validators/user.js b/core/client/validators/user.js index 4f345b2500..7ab0f83a0d 100644 --- a/core/client/validators/user.js +++ b/core/client/validators/user.js @@ -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'}); } diff --git a/core/server/models/user.js b/core/server/models/user.js index 0dd2f73fed..944a65fa68 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -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'); },