-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] RocketChat.settings.get causing memory leak (sometimes) (#11487)
<!-- INSTRUCTION: Your Pull Request name should start with one of the following tags --> <!-- [NEW] For new features --> <!-- [FIX] For bug fixes --> <!-- [BREAK] For pull requests including breaking changes --> <!-- INSTRUCTION: Inform the issue number that this PR closes, or remove the line below --> <!-- INSTRUCTION: Link to a https://github.com/RocketChat/docs PR with added/updated documentation or an update to the missing/outdated documentation list, see https://rocket.chat/docs/contributing/documentation/ --> <!-- INSTRUCTION: Tell us more about your PR with screen shots if you can -->
- Loading branch information
Showing
2 changed files
with
29 additions
and
26 deletions.
There are no files selected for viewing
39 changes: 21 additions & 18 deletions
39
packages/rocketchat-lib/server/functions/checkUsernameAvailability.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
import _ from 'underscore'; | ||
import s from 'underscore.string'; | ||
|
||
|
||
let usernameBlackList = []; | ||
|
||
const toRegExp = username => new RegExp(`^${ s.escapeRegExp(username).trim() }$`, 'i'); | ||
|
||
RocketChat.settings.get('Accounts_BlockedUsernameList', (key, value) => { | ||
usernameBlackList = value.split(',').map(toRegExp); | ||
}); | ||
|
||
const usernameIsBlocked = (username, usernameBlackList) => usernameBlackList.length | ||
&& usernameBlackList.some(restrictedUsername => restrictedUsername.test(s.trim(s.escapeRegExp(username)))); | ||
|
||
RocketChat.checkUsernameAvailability = function(username) { | ||
return RocketChat.settings.get('Accounts_BlockedUsernameList', function(key, value) { | ||
const usernameBlackList = _.map(value.split(','), function(username) { | ||
return username.trim(); | ||
}); | ||
if (usernameBlackList.length !== 0) { | ||
if (usernameBlackList.every(restrictedUsername => { | ||
const regex = new RegExp(`^${ s.escapeRegExp(restrictedUsername) }$`, 'i'); | ||
return !regex.test(s.trim(s.escapeRegExp(username))); | ||
})) { | ||
return !Meteor.users.findOne({ | ||
username: { | ||
$regex: new RegExp(`^${ s.trim(s.escapeRegExp(username)) }$`, 'i') | ||
} | ||
}); | ||
} | ||
return false; | ||
|
||
if (usernameIsBlocked(username, usernameBlackList)) { | ||
return false; | ||
} | ||
|
||
return !Meteor.users.findOne({ | ||
username: { | ||
$regex: toRegExp(username) | ||
} | ||
}); | ||
}, { fields: { _id: 1 } }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters