From 457f3e4e81bc90f74c2e57fd5b65aea3e2bfe5fb Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 19 Nov 2024 15:24:47 +0300 Subject: [PATCH 1/3] fixed short mention regex --- src/CONST.ts | 5 ++++- tests/unit/ShortMentionRegexTest.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/unit/ShortMentionRegexTest.ts diff --git a/src/CONST.ts b/src/CONST.ts index faa3d35a5e06..b3ba99a5736a 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2995,7 +2995,10 @@ 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( + `(? { + 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)), + ); + }); +}); From 212c42f14a1b63a9babdc40be43beb74f45e809f Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 20 Nov 2024 23:00:36 +0300 Subject: [PATCH 2/3] added comment --- src/CONST.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index b3ba99a5736a..8f2078af590e 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2996,6 +2996,8 @@ const CONST = { PATH_WITHOUT_POLICY_ID: /\/w\/[a-zA-Z0-9]+(\/|$)/, POLICY_ID_FROM_PATH: /\/w\/([a-zA-Z0-9]+)(\/|$)/, 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. `(? Date: Mon, 20 Jan 2025 18:39:04 +0300 Subject: [PATCH 3/3] fix logic --- src/CONST.ts | 2 +- tests/unit/ShortMentionRegexTest.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 23bd05c77d89..19c88214eecf 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3111,7 +3111,7 @@ const CONST = { 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', + '`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', + '`sd` `` g @short@test.co\n`sd` `` g @short@test.co `\n`jkl @short-mention `jk` \n`sd` g @short@test.co\n`jkl @short-mention`', + '`jkl` ``sth @short-mention@test.co jk`\n`jkl` ``sth`@short-mention` 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 ``\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) =>