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' ==== //