diff --git a/src/groups.js b/src/groups.js index fbca035cba..7498ea4a2c 100644 --- a/src/groups.js +++ b/src/groups.js @@ -57,30 +57,24 @@ var utils = require('../public/src/utils'); }; Groups.getGroupsFromSet = function (set, uid, start, stop, callback) { - var method; - var args; - if (set === 'groups:visible:name') { - method = db.getSortedSetRangeByLex; - args = [set, '-', '+', start, stop - start + 1, done]; - } else { - method = db.getSortedSetRevRange; - args = [set, start, stop, done]; - } - method.apply(null, args); - - function done(err, groupNames) { - if (err) { - return callback(err); - } + async.waterfall([ + function (next) { + if (set === 'groups:visible:name') { + db.getSortedSetRangeByLex(set, '-', '+', start, stop - start + 1, next); + } else { + db.getSortedSetRevRange(set, start, stop, next); + } + }, + function (groupNames, next) { + if (set === 'groups:visible:name') { + groupNames = groupNames.map(function (name) { + return name.split(':')[1]; + }); + } - if (set === 'groups:visible:name') { - groupNames = groupNames.map(function (name) { - return name.split(':')[1]; - }); + Groups.getGroupsAndMembers(groupNames, next); } - - Groups.getGroupsAndMembers(groupNames, callback); - } + ], callback); }; Groups.getGroups = function (set, start, stop, callback) { diff --git a/src/groups/create.js b/src/groups/create.js index 1d16ea33cf..a59567afe6 100644 --- a/src/groups/create.js +++ b/src/groups/create.js @@ -92,6 +92,10 @@ module.exports = function (Groups) { return callback(new Error('[[error:group-name-too-long]]')); } + if (!Groups.isPrivilegeGroup(name) && name.indexOf(':') !== -1) { + return callback(new Error('[[error:invalid-group-name]]')); + } + if (name.indexOf('/') !== -1 || !utils.slugify(name)) { return callback(new Error('[[error:invalid-group-name]]')); } diff --git a/test/groups.js b/test/groups.js index 182910bc32..81d37ed833 100644 --- a/test/groups.js +++ b/test/groups.js @@ -255,6 +255,13 @@ describe('Groups', function () { done(); }); }); + + it('should fail if group name is invalid', function (done) { + Groups.create({name: 'not:valid'}, function (err) { + assert.equal(err.message, '[[error:invalid-group-name]]'); + done(); + }); + }); }); describe('.hide()', function () {