Skip to content

Commit 7b9fa18

Browse files
authored
fix: Queries with object field authData.provider.id are incorrectly transformed to _auth_data_provider.id for custom classes (parse-community#9932)
1 parent 8ff1d89 commit 7b9fa18

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

spec/MongoTransform.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,23 @@ describe('parseObjectToMongoObjectForCreate', () => {
521521
expect(output.authData).toBe('random');
522522
done();
523523
});
524+
525+
it('should only transform authData.provider.id for _User class', () => {
526+
// Test that for _User class, authData.facebook.id is transformed
527+
const userInput = {
528+
'authData.facebook.id': '10000000000000001',
529+
};
530+
const userOutput = transform.transformWhere('_User', userInput, { fields: {} });
531+
expect(userOutput['_auth_data_facebook.id']).toBe('10000000000000001');
532+
533+
// Test that for non-User classes, authData.facebook.id is NOT transformed
534+
const customInput = {
535+
'authData.facebook.id': '10000000000000001',
536+
};
537+
const customOutput = transform.transformWhere('SpamAlerts', customInput, { fields: {} });
538+
expect(customOutput['authData.facebook.id']).toBe('10000000000000001');
539+
expect(customOutput['_auth_data_facebook.id']).toBeUndefined();
540+
});
524541
});
525542

526543
it('cannot have a custom field name beginning with underscore', done => {

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function transformQueryKeyValue(className, key, value, schema, count = false) {
305305
default: {
306306
// Other auth data
307307
const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
308-
if (authDataMatch) {
308+
if (authDataMatch && className === '_User') {
309309
const provider = authDataMatch[1];
310310
// Special-case auth data.
311311
return { key: `_auth_data_${provider}.id`, value };

0 commit comments

Comments
 (0)