summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-03-13 12:50:57 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-03-13 12:50:57 +0000
commitc90b21f8ba4d2d044836477323ee4504163eb9d5 (patch)
tree9b71d9ecb54c24084d5407284423eeb7b710b1f1
parent2ffacd49268f745a3e854353e4179011dc646c70 (diff)
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
-rw-r--r--src/couchdb/couch_js_functions.hrl48
1 files changed, 25 insertions, 23 deletions
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.');
+ }
}
}
}