diff --git a/src/CONST.ts b/src/CONST.ts index 496b7d8b28ec..7ddbbc6df72f 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3028,7 +3028,12 @@ const CONST = { REPORT_FIELD_TITLE: /{report:([a-zA-Z]+)}/g, PATH_WITHOUT_POLICY_ID: /\/w\/[a-zA-Z0-9]+(\/|$)/, POLICY_ID_FROM_PATH: /\/w\/([a-zA-Z0-9]+)(\/|$)/, - SHORT_MENTION: new RegExp(`@[\\w\\-\\+\\'#@]+(?:\\.[\\w\\-\\'\\+]+)*(?![^\`]*\`)`, 'gim'), + SHORT_MENTION: new RegExp( + // We are ensuring that the short mention is not inside a code block. So we check that the short mention + // is either not preceded by an open code block or not followed by a backtick on the same line. + `(? { + it('Should concat the private domain to proper short mentions only', () => { + const testTexts = [ + '`sd` `` g @short\n`sd` `` g @short `\n`jkl @short-mention `jk` \n`sd` g @short\n`jkl @short-mention`', + '`jkl` ``sth @short-mention jk`\n`jkl` ``sth`@short-mention` jk`\n`jkl @short-mention jk\n`jkl @short-mention jk\nj`k`l @short-mention jk', + '`jk`l @short-mention`sd `g @short`jk`l @short-mention`sd g @short\n`jk`l `@short-mention`sd g @short`jk`l @short-mention`sd g @short\njkl @short-mention`sd `g @short`jk`l @short-mention`sd g @short\n`jkl @short-mention`sd `g @short`jk`l @short-mention`sd g @short', + ]; + const expectedValues = [ + '`sd` `` g @short@test.co\n`sd` `` g @short `\n`jkl @short-mention `jk` \n`sd` g @short@test.co\n`jkl @short-mention`', + '`jkl` ``sth @short-mention jk`\n`jkl` ``sth`@short-mention@test.co` jk`\n`jkl @short-mention@test.co jk\n`jkl @short-mention@test.co jk\nj`k`l @short-mention@test.co jk', + '`jk`l @short-mention@test.co`sd `g @short@test.co`jk`l @short-mention@test.co`sd g @short@test.co\n`jk`l `@short-mention`sd g @short@test.co`jk`l @short-mention@test.co`sd g @short@test.co\njkl @short-mention@test.co`sd `g @short@test.co`jk`l @short-mention@test.co`sd g @short@test.co\n`jkl @short-mention`sd `g @short`jk`l @short-mention`sd g @short@test.co', + ]; + + testTexts.forEach((text, i) => + expect( + text.replace(CONST.REGEX.SHORT_MENTION, (match) => { + if (!Str.isValidMention(match)) { + return match; + } + return `${match}@test.co`; + }), + ).toEqual(expectedValues.at(i)), + ); + }); +});