From c90b21f8ba4d2d044836477323ee4504163eb9d5 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Sun, 13 Mar 2011 12:50:57 +0000 Subject: Merged revision 1081096 from trunk Replicator database: only validate user_ctx if doc is not being deleted git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1081104 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_js_functions.hrl | 48 ++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/couch_js_functions.hrl b/src/couchdb/couch_js_functions.hrl index 31d5b598..6c2ad8df 100644 --- a/src/couchdb/couch_js_functions.hrl +++ b/src/couchdb/couch_js_functions.hrl @@ -176,38 +176,40 @@ reportError('The `query_params\\' field must be an object.'); } - } - if (newDoc.user_ctx) { - var user_ctx = newDoc.user_ctx; + if (newDoc.user_ctx) { + var user_ctx = newDoc.user_ctx; - if (typeof user_ctx !== 'object') { - reportError('The `user_ctx\\' property must be an object.'); - } + if ((typeof user_ctx !== 'object') || (user_ctx === null)) { + reportError('The `user_ctx\\' property must be a ' + + 'non-null object.'); + } - if (!(user_ctx.name === null || + if (!(user_ctx.name === null || (typeof user_ctx.name === 'undefined') || ((typeof user_ctx.name === 'string') && user_ctx.name.length > 0))) { - reportError('The `user_ctx.name\\' property must be a ' + - 'non-empty string.'); - } - if (user_ctx.roles && !isArray(user_ctx.roles)) { - reportError('The `user_ctx.roles\\' property must be ' + - 'an array of strings.'); - } + reportError('The `user_ctx.name\\' property must be a ' + + 'non-empty string or null.'); + } - if (user_ctx.roles) { - for (var i = 0; i < user_ctx.roles.length; i++) { - var role = user_ctx.roles[i]; + if (user_ctx.roles && !isArray(user_ctx.roles)) { + reportError('The `user_ctx.roles\\' property must be ' + + 'an array of strings.'); + } - if (typeof role !== 'string' || role.length === 0) { - reportError('Each role must be a non-empty string.'); - } - if (role[0] === '_') { - reportError('System roles (starting with underscore) ' + - 'are not allowed.'); + if (user_ctx.roles) { + for (var i = 0; i < user_ctx.roles.length; i++) { + var role = user_ctx.roles[i]; + + if (typeof role !== 'string' || role.length === 0) { + reportError('Roles must be non-empty strings.'); + } + if (role[0] === '_') { + reportError('System roles (starting with an ' + + 'underscore) are not allowed.'); + } } } } -- cgit v1.2.3