From 251798c7115f037fbeff2d873089bdf6fdf7cd5f Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Thu, 30 Aug 2018 04:57:37 +0200 Subject: [PATCH] fix: ignore extra properties when strict=filter (#1423) Fix for #1422 --- lib/dao.js | 2 +- test/manipulation.test.js | 14 ++++++++++++++ test/model-inheritance.test.js | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/dao.js b/lib/dao.js index 65d9fc38..36f87f0f 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -93,7 +93,7 @@ function applyStrictCheck(model, strict, data, inst, cb) { key = keys[i]; if (props[key]) { result[key] = data[key]; - } else if (strict) { + } else if (strict && strict !== 'filter') { inst.__unknownProperties.push(key); } } diff --git a/test/manipulation.test.js b/test/manipulation.test.js index 1c4fa7d4..395c3b69 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -633,6 +633,20 @@ describe('manipulation', function() { }); }); + it('should remove unknown attributes when strict: filter', + function(done) { + Person.definition.settings.strict = 'filter'; + Person.findById(person.id, function(err, p) { + if (err) return done(err); + p.updateAttributes({name: 'John', foo: 'bar'}, + function(err, p) { + if (err) return done(err); + p.should.not.have.property('foo'); + done(); + }); + }); + }); + // Prior to version 3.0 `strict: true` used to silently remove unknown properties, // now return validationError upon unknown properties it('should return error on unknown attributes when strict: true', diff --git a/test/model-inheritance.test.js b/test/model-inheritance.test.js index baccd347..bb580170 100644 --- a/test/model-inheritance.test.js +++ b/test/model-inheritance.test.js @@ -73,7 +73,7 @@ describe('Model class inheritance', function() { relations: {patch: true}, }; - // saving original getMergePolicy method + // saving original getMergePolicy method let originalGetMergePolicy = base.getMergePolicy; // the injected getMergePolicy method captures the provided configureModelMerge option