File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
package/src/components/Message/MessageSimple/utils Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -108,4 +108,10 @@ getstream.io
108108
109109 expect ( result ) . toHaveLength ( 0 ) ;
110110 } ) ;
111+
112+ it . each ( [ [ '@user' ] , [ '@user.name' ] ] ) ( 'does not parse %p as a URL' , ( input ) => {
113+ const result = parseLinksFromText ( input ) ;
114+
115+ expect ( result ) . toHaveLength ( 0 ) ;
116+ } ) ;
111117} ) ;
Original file line number Diff line number Diff line change @@ -43,10 +43,19 @@ interface Link {
4343 * */
4444const removeMarkdownLinksFromText = ( input : string ) => input . replace ( / \[ [ \w \s ] + \] \( .* \) / g, '' ) ;
4545
46+ /**
47+ * Hermes doesn't support lookbehind, so this is done separately to avoid
48+ * parsing user names as links.
49+ * */
50+ const removeUserNamesFromText = ( input : string ) => input . replace ( / ^ @ \w + \. ? \w / , '' ) ;
51+
4652export const parseLinksFromText = ( input : string ) : Link [ ] => {
4753 let matches ;
4854
49- const inputWithoutMarkdownLinks = removeMarkdownLinksFromText ( input ) ;
55+ const strippedInput = [ removeMarkdownLinksFromText , removeUserNamesFromText ] . reduce (
56+ ( acc , fn ) => fn ( acc ) ,
57+ input ,
58+ ) ;
5059
5160 const results : Link [ ] = [ ] ;
5261
@@ -61,7 +70,7 @@ export const parseLinksFromText = (input: string): Link[] => {
6170 * to avoid overlapping matches being duplicated in the output.
6271 * */
6372 const linkRegex = new RegExp ( `${ fqdnLinkPattern } |${ schemePrefixedLinkPattern } ` , 'gi' ) ;
64- while ( ( matches = linkRegex . exec ( inputWithoutMarkdownLinks ) ) !== null ) {
73+ while ( ( matches = linkRegex . exec ( strippedInput ) ) !== null ) {
6574 const [
6675 raw ,
6776 fqdnScheme = '' ,
You can’t perform that action at this time.
0 commit comments