Skip to content

Commit

Permalink
Fix enableCollationCaseComparison, caseInsensitive and test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattia1208 committed Nov 12, 2023
1 parent 7bff03c commit c8b6129
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion spec/DatabaseController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ describe('DatabaseController', function () {
it('should not find a case insensitive user by email with convertEmailToLowercase', async () => {
await reconfigureServer({ convertEmailToLowercase: true });
const user = new Parse.User();
await user.save({ email: '[email protected]', password: 'password' });
await user.save({ username: 'EXAMPLE', email: '[email protected]', password: 'password' });

const query = new Parse.Query(Parse.User);
query.equalTo('email', '[email protected]');
Expand Down
30 changes: 16 additions & 14 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ class DatabaseController {
keys,
readPreference,
hint,
caseInsensitive,
caseInsensitive: this.options.enableCollationCaseComparison ? false : caseInsensitive,
explain,
};
Object.keys(sort).forEach(fieldName => {
Expand Down Expand Up @@ -1739,25 +1739,27 @@ class DatabaseController {
throw error;
});

await this.adapter
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
.catch(error => {
logger.warn('Unable to create case insensitive username index: ', error);
throw error;
});
if (!this.options.enableCollationCaseComparison) {
await this.adapter
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
.catch(error => {
logger.warn('Unable to create case insensitive username index: ', error);
throw error;
});

await this.adapter
.ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true)
.catch(error => {
logger.warn('Unable to create case insensitive email index: ', error);
throw error;
});
}

await this.adapter.ensureUniqueness('_User', requiredUserFields, ['email']).catch(error => {
logger.warn('Unable to ensure uniqueness for user email addresses: ', error);
throw error;
});

await this.adapter
.ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true)
.catch(error => {
logger.warn('Unable to create case insensitive email index: ', error);
throw error;
});

await this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name']).catch(error => {
logger.warn('Unable to ensure uniqueness for role name: ', error);
throw error;
Expand Down

0 comments on commit c8b6129

Please sign in to comment.