Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
e0c562bf
Unverified
Commit
e0c562bf
authored
Jan 02, 2020
by
Benjamin Wheeler
Committed by
GitHub
Jan 02, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3484 from benjiwheeler/join-flow-count-unicode
count unicode characters as single characters
parents
5a24a9d8
4c0026ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
+32
-7
src/lib/validate.js
src/lib/validate.js
+9
-1
test/unit/lib/validate.test.js
test/unit/lib/validate.test.js
+23
-6
No files found.
src/lib/validate.js
View file @
e0c562bf
...
...
@@ -57,7 +57,15 @@ module.exports.validateUsernameRemotely = username => (
module
.
exports
.
validatePassword
=
(
password
,
username
)
=>
{
if
(
!
password
)
{
return
{
valid
:
false
,
errMsgId
:
'
general.required
'
};
}
else
if
(
password
.
length
<
6
)
{
// Using Array.from(string).length, instead of string.length, improves unicode
// character counting for a subset of unicode characters, so that they are counted
// as single characters by js.
// However, this only helps with a subset of unicode. Characters combinations,
// including diacritical marks or skintone/gender variations, will still appear
// to be multiple characters. See discussions:
// https://blog.jonnew.com/posts/poo-dot-length-equals-two
// 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
'
};
...
...
test/unit/lib/validate.test.js
View file @
e0c562bf
...
...
@@ -52,21 +52,38 @@ describe('unit test lib/validate.js', () => {
expect
(
response
).
toEqual
({
valid
:
false
,
errMsgId
:
'
registration.validationUsernameRegexp
'
});
});
test
(
'
validate password
'
,
()
=>
{
test
(
'
validate password
existence
'
,
()
=>
{
let
response
;
expect
(
typeof
validate
.
validatePassword
).
toBe
(
'
function
'
);
response
=
validate
.
validatePassword
(
'
abcdef
'
);
expect
(
response
).
toEqual
({
valid
:
true
});
response
=
validate
.
validatePassword
(
'
abcdefghijklmnopqrst
'
);
expect
(
response
).
toEqual
({
valid
:
true
});
response
=
validate
.
validatePassword
(
'
passwo
'
);
expect
(
response
).
toEqual
({
valid
:
true
});
response
=
validate
.
validatePassword
(
''
);
expect
(
response
).
toEqual
({
valid
:
false
,
errMsgId
:
'
general.required
'
});
});
test
(
'
validate password length
'
,
()
=>
{
let
response
;
response
=
validate
.
validatePassword
(
'
abcdefghijklmnopqrst
'
);
expect
(
response
).
toEqual
({
valid
:
true
});
response
=
validate
.
validatePassword
(
'
abcde
'
);
expect
(
response
).
toEqual
({
valid
:
false
,
errMsgId
:
'
registration.validationPasswordLength
'
});
response
=
validate
.
validatePassword
(
'
password
'
);
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
});
});
test
(
'
validate password cannot be "password"
'
,
()
=>
{
const
response
=
validate
.
validatePassword
(
'
password
'
);
expect
(
response
).
toEqual
({
valid
:
false
,
errMsgId
:
'
registration.validationPasswordNotEquals
'
});
});
test
(
'
validate password cannot be same as username
'
,
()
=>
{
let
response
;
response
=
validate
.
validatePassword
(
'
abcdefg
'
,
'
abcdefg
'
);
expect
(
response
).
toEqual
({
valid
:
false
,
errMsgId
:
'
registration.validationPasswordNotUsername
'
});
response
=
validate
.
validatePassword
(
'
abcdefg
'
,
'
abcdefG
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment