diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index dd7571c1..2347c161 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -697,6 +697,7 @@ test('Test url replacements', () => { '@test.com test.com ' + '@test.com @test.com '; + // Fixme [short-mention] this errors on "test.com @test.com @test.com { }, ]; - // Fixme @expensify.com is a now correct "possible" short mention + // Fixme [short-mention] @expensify.com should now be considered a short-mention "candidate" testCases.forEach((testCase) => { expect(parser.replace(testCase.testString)).toBe(testCase.resultString); }); @@ -1321,10 +1322,6 @@ test('Test for user mention with @username@domain.com', () => { const resultString = '@username@expensify.com'; expect(parser.replace(testString)).toBe(resultString); }); -// Todo -// popraw psujący się @here testy -// Todo wszystkie edge kejsy w których short mention jest ambiguous -// short-mention -> possible-short-mention test('Test for short mention mention with @username@domain.com', () => { const testString = '@john.doe'; @@ -1515,6 +1512,7 @@ test('Test for @here mention with italic, bold and strikethrough styles', () => ' @here!' + ' @here?'; + // Fixme [short-mention] these should now be short-mention candidates const resultString = '@here' + ' @here' + diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index 11812a08..325747b0 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -414,29 +414,6 @@ export default class ExpensiMark { }, }, - { - name: 'shortMentions', - regex: new RegExp( - "(@here|[a-zA-Z0-9.!$%&+=?^\\`{|}-]?)(@(?=((?=[\\w]+[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*)[\\w\\.'#%+-]{1,64}(?= |_|\\b))(?!([:\\/\\\\]))(?.*))\\S{3,254}(?=\\k$))(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>|<\\/mention-user>|<\\/mention-here>))", - 'gim', - ), - replacement: (_extras, match, g1, g2) => { - if (!Str.isValidMention(match)) { - return match; - } - return `${g1}${g2}`; - }, - // rawInputReplacement: (_extras, match, g1, g2) => { - // const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`); - // const mention = g2.slice(1); - // const mentionWithoutSMSDomain = str_1.default.removeSMSDomain(mention); - // if (!str_1.default.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !str_1.default.isValidPhoneNumber(mentionWithoutSMSDomain))) { - // return match; - // } - // return `${g1}${g2}`; - // }, - }, - { name: 'quote', @@ -504,6 +481,30 @@ export default class ExpensiMark { rawInputReplacement: '$1$2', }, + { + name: 'shortMentions', + + regex: new RegExp( + "(@here|[a-zA-Z0-9.!$%&+=?^\\`{|}-]?)(@(?=((?=[\\w]+[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*)[\\w\\.'#%+-]{1,64}(?= |_|\\b))(?!([:\\/\\\\]))(?.*))\\S{3,254}(?=\\k$))(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>|<\\/mention-user>|<\\/mention-here>))", + 'gim', + ), + replacement: (_extras, match, g1, g2) => { + if (!Str.isValidMention(match)) { + return match; + } + return `${g1}${g2}`; + }, + // rawInputReplacement: (_extras, match, g1, g2) => { + // const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`); + // const mention = g2.slice(1); + // const mentionWithoutSMSDomain = str_1.default.removeSMSDomain(mention); + // if (!str_1.default.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !str_1.default.isValidPhoneNumber(mentionWithoutSMSDomain))) { + // return match; + // } + // return `${g1}${g2}`; + // }, + }, + { // Use \B in this case because \b doesn't match * or ~. // \B will match everything that \b doesn't, so it works