react-native-controlled-mentions icon indicating copy to clipboard operation
react-native-controlled-mentions copied to clipboard

replaceMentionValues not working with multi mentions inside string

Open fukemy opened this issue 2 years ago • 5 comments

for example i have below string:

@[demo5](d3f0c3cd-f363-4303-8761-8e190f054be3) @[demo8](8dbafd40-b86f-490a-828d-d11dfe221b43) test

then

params.Msg.Text = replaceMentionValues(text, ({name}) =>  `@${name}`)

result: @demo5 @[demo8](8dbafd40-b86f-490a-828d-d11dfe221b43) test

fukemy avatar Jul 27 '22 04:07 fukemy

I can reproduce this issue. The issue appears only in 3.0.0-alpha.2. It works in 3.0.0-alpha.1.

pgrepds avatar Jul 27 '22 09:07 pgrepds

thanks, @dabakovich plz update the problem

fukemy avatar Jul 27 '22 09:07 fukemy

waiting. for @dabakovich confirm

fukemy avatar Jul 27 '22 10:07 fukemy

The cause of this issue is located in constraints.ts in 3.0.0-alpha.2 which defines the following regex: const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/i;. In 3.0.0-alpha.1 the used regex is located in utils.ts and is as follows: const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/gi;. The delimiter is not global anymore, thus not all words will be matched.

pgrepds avatar Jul 27 '22 10:07 pgrepds

It seems to be fixed in the newest version of the 3.0 branch. The function is renamed to replaceTriggerValues and adds the g to the regex. There is a test case in utils.test. I guess you can either downgrade to alpha 1 or use the newest version of the 3.0 branch (but the matching pattern seems to have changed a little bit).

pgrepds avatar Jul 27 '22 10:07 pgrepds