Merge pull request #27860 from overleaf/lg-spam-safe

Add spam check for incident

GitOrigin-RevId: 752180f7507e32219cc5faaef5d48fdc0003e889
This commit is contained in:
Christopher Hoskin
2025-08-12 21:07:31 +01:00
committed by Copybot
parent 447efbd5b1
commit ca30fdd95c
2 changed files with 15 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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')