Skip to content

Commit

Permalink
Validation function for version numbers, and checking dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbisbee committed Apr 20, 2011
1 parent 65c4a7e commit 382f6e4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions couchdb/app/validate_doc_update.js
Expand Up @@ -32,6 +32,15 @@ function (newDoc, oldDoc, userCtx) {
if(obj.constructor != Object) forbidden(message);
};

function requireVersion(str, message) {
requireString(str, message);

var ver = str.split('.');

if(ver.length != 3 || isNaN(ver[0]) || isNaN(ver[1]) || isNaN(ver[2]))
forbidden(message);
};

// Default Values

if(!doc.clone)
Expand Down Expand Up @@ -85,6 +94,16 @@ function (newDoc, oldDoc, userCtx) {

if(doc.dependencies)
{
var dependenciesError = '"dependencies" should be an object of project names to arrays of version numbers.';

requireObject(doc.dependencies, dependenciesError);

for(var i in doc.dependencies)
{
requireArray(doc.dependencies[i], dependenciesError);

for(var j in doc.dependencies[i])
requireVersion(doc.dependencies[i][j], dependenciesError);
}
}
}

0 comments on commit 382f6e4

Please sign in to comment.