diff --git a/spec/ParseAPI.spec.js b/spec/ParseAPI.spec.js index be0fe5b2f2..d7ab20af77 100644 --- a/spec/ParseAPI.spec.js +++ b/spec/ParseAPI.spec.js @@ -1306,7 +1306,7 @@ it('ensure that if you try to sign up a user with a unique username and email, b }); }); - it_exclude_dbs(['postgres'])('bans interior keys containing . or $', done => { + it('bans interior keys containing . or $', done => { new Parse.Object('Obj').save({innerObj: {'key with a $': 'fails'}}) .then(() => { fail('should not succeed') diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 48e9233db8..fcc9a4c77f 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -136,6 +136,20 @@ const handleDotFields = (object) => { return object; } +const validateKeys = (object) => { + if (typeof object == 'object') { + for (const key in object) { + if (typeof object[key] == 'object') { + validateKeys(object[key]); + } + + if(key.includes('$') || key.includes('.')){ + throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters"); + } + } + } +} + // Returns the list of join tables on a schema const joinTablesForSchema = (schema) => { let list = []; @@ -649,6 +663,8 @@ export class PostgresStorageAdapter { object = handleDotFields(object); + validateKeys(object); + Object.keys(object).forEach(fieldName => { var authDataMatch = fieldName.match(/^_auth_data_([a-zA-Z0-9_]+)$/); if (authDataMatch) {