mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #27860 from overleaf/lg-spam-safe
Add spam check for incident GitOrigin-RevId: 752180f7507e32219cc5faaef5d48fdc0003e889
This commit is contained in:
committed by
Copybot
parent
447efbd5b1
commit
ca30fdd95c
@@ -11,6 +11,11 @@ const XRegExp = require('xregexp')
|
||||
const HAN_REGEX = XRegExp('\\p{Han}')
|
||||
const SAFE_REGEX = XRegExp("^[\\p{L}\\p{N}\\s\\-_!'&\\(\\)]+$")
|
||||
const EMAIL_REGEX = XRegExp('^[\\p{L}\\p{N}.+_-]+@[\\w.-]+$')
|
||||
const SPAM_TAGS_REGEX = /qun|jiaqun|jia|jnd/i
|
||||
|
||||
function countDigits(str) {
|
||||
return (str.match(/\d/g) || []).length
|
||||
}
|
||||
|
||||
const SpamSafe = {
|
||||
isSafeUserName(name) {
|
||||
@@ -18,6 +23,10 @@ const SpamSafe = {
|
||||
},
|
||||
|
||||
isSafeProjectName(name) {
|
||||
if (SPAM_TAGS_REGEX.test(name) || countDigits(name) > 5) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (HAN_REGEX.test(name)) {
|
||||
return SAFE_REGEX.test(name) && name.length <= 10
|
||||
}
|
||||
|
||||
@@ -60,6 +60,12 @@ describe('SpamSafe', function () {
|
||||
'A Project'
|
||||
)
|
||||
).to.equal('A Project')
|
||||
expect(SpamSafe.safeProjectName(`JND-123456-100s68`, 'A Project')).to.equal(
|
||||
'A Project'
|
||||
)
|
||||
expect(
|
||||
SpamSafe.safeProjectName(`JiAqun123456s100sf68`, 'A Project')
|
||||
).to.equal('A Project')
|
||||
expect(
|
||||
SpamSafe.safeEmail('safe-ëmail@domain.com', 'A collaborator')
|
||||
).to.equal('safe-ëmail@domain.com')
|
||||
|
||||
Reference in New Issue
Block a user