mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 15:17:53 -05:00
count unicode characters as single characters
This commit is contained in:
parent
9221b6f6b5
commit
6bf27b7e8a
2 changed files with 11 additions and 1 deletions
|
@ -50,7 +50,9 @@ module.exports.validateUsernameRemotely = username => (
|
|||
module.exports.validatePassword = (password, username) => {
|
||||
if (!password) {
|
||||
return {valid: false, errMsgId: 'general.required'};
|
||||
} else if (password.length < 6) {
|
||||
// get length of password, considering unicode symbols as single chars.
|
||||
// see discussion at https://stackoverflow.com/a/54370584/2308190
|
||||
} else if (Array.from(password).length < 6) {
|
||||
return {valid: false, errMsgId: 'registration.validationPasswordLength'};
|
||||
} else if (password === 'password') {
|
||||
return {valid: false, errMsgId: 'registration.validationPasswordNotEquals'};
|
||||
|
|
|
@ -39,6 +39,14 @@ describe('unit test lib/validate.js', () => {
|
|||
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'});
|
||||
response = validate.validatePassword('password');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordNotEquals'});
|
||||
response = validate.validatePassword('😺');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'});
|
||||
response = validate.validatePassword('😺🦆🐝');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'});
|
||||
response = validate.validatePassword('😺🦆🐝🐮🐠');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'});
|
||||
response = validate.validatePassword('😺🦆🐝🐮🐠🐻');
|
||||
expect(response).toEqual({valid: true});
|
||||
response = validate.validatePassword('abcdefg', 'abcdefg');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordNotUsername'});
|
||||
response = validate.validatePassword('abcdefg', 'abcdefG');
|
||||
|
|
Loading…
Reference in a new issue