From 0476c151639f44db80f8d5d6055d490cc7d1d0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Mon, 8 Apr 2019 12:08:49 +0200 Subject: [PATCH] Remove dots from matched @mention regex --- backend/src/middleware/notifications/mentions.js | 2 +- .../src/middleware/notifications/mentions.spec.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/src/middleware/notifications/mentions.js b/backend/src/middleware/notifications/mentions.js index fb4a049f2..7071c9313 100644 --- a/backend/src/middleware/notifications/mentions.js +++ b/backend/src/middleware/notifications/mentions.js @@ -1,4 +1,4 @@ -const MENTION_REGEX = /\s@(\S+)/g +const MENTION_REGEX = /\s@([\w_-]+)/g export function extractSlugs(content) { let slugs = [] diff --git a/backend/src/middleware/notifications/mentions.spec.js b/backend/src/middleware/notifications/mentions.spec.js index 8fe9221b3..0c70aae1c 100644 --- a/backend/src/middleware/notifications/mentions.spec.js +++ b/backend/src/middleware/notifications/mentions.spec.js @@ -6,6 +6,21 @@ describe('extract', () => { const content = 'Hello @user' expect(extractSlugs(content)).toEqual(['user']) }) + + it('@user-with-dash', () => { + const content = 'Hello @user-with-dash' + expect(extractSlugs(content)).toEqual(['user-with-dash']) + }) + + it('@user.', () => { + const content = 'Hello @user.' + expect(extractSlugs(content)).toEqual(['user']) + }) + + it('@user-With-Capital-LETTERS', () => { + const content = 'Hello @user-With-Capital-LETTERS' + expect(extractSlugs(content)).toEqual(['user-With-Capital-LETTERS']) + }) }) it('ignores email addresses', () => {