From cf09a75be3537161dc2da37777ac82a872c36a4d Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Wed, 15 May 2013 17:37:35 +0200 Subject: [PATCH] Field names cannot contain a dot --- lib/model.js | 6 +++++- test/model.test.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/model.js b/lib/model.js index 9f12a0e..7f55934 100644 --- a/lib/model.js +++ b/lib/model.js @@ -20,7 +20,11 @@ var dateToJSON = function () { return { $$date: this.getTime() }; } */ function checkKey (k, v) { if (k[0] === '$' && !(k === '$$date' && typeof v === 'number')) { - throw 'Keys cannot begin with the $ character'; + throw 'Field names cannot begin with the $ character'; + } + + if (k.indexOf('.') !== -1) { + throw 'Field names cannot contain a .'; } } diff --git a/test/model.test.js b/test/model.test.js index 42490f8..65c3991 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -148,6 +148,16 @@ describe('Model', function () { }).should.throw(); }); + it('Field names cannot contain a .', function () { + assert.isDefined(model.checkObject); + + (function () { + model.checkObject({ "so.bad": true }); + }).should.throw(); + + // Recursive behaviour testing done in the above test on $ signs + }); + }); // ==== End of 'Object checking' ==== //