diff --git a/projects/stream-chat-angular/src/lib/message/message.component.spec.ts b/projects/stream-chat-angular/src/lib/message/message.component.spec.ts
index 03810176..61af282c 100644
--- a/projects/stream-chat-angular/src/lib/message/message.component.spec.ts
+++ b/projects/stream-chat-angular/src/lib/message/message.component.spec.ts
@@ -930,6 +930,28 @@ describe('MessageComponent', () => {
expect(component.messageTextParts![0].content).toContain(
'https://getstream.io/'
);
+
+ component.message.text = 'This is a message with a link google.com';
+ component.ngOnChanges({ message: {} as SimpleChange });
+
+ expect(component.messageTextParts![0].content).toContain(
+ 'google.com'
+ );
+
+ component.message.text = 'This is a message with a link www.google.com';
+ component.ngOnChanges({ message: {} as SimpleChange });
+
+ expect(component.messageTextParts![0].content).toContain(
+ 'www.google.com'
+ );
+
+ component.message.text =
+ 'This is a message with a link file:///C:/Users/YourName/Documents/example.txt';
+ component.ngOnChanges({ message: {} as SimpleChange });
+
+ expect(component.messageTextParts![0].content).toContain(
+ 'file:///C:/Users/YourName/Documents/example.txt'
+ );
});
it('should display reply count for parent messages', () => {
diff --git a/projects/stream-chat-angular/src/lib/message/message.component.ts b/projects/stream-chat-angular/src/lib/message/message.component.ts
index d2309b37..f832dabc 100644
--- a/projects/stream-chat-angular/src/lib/message/message.component.ts
+++ b/projects/stream-chat-angular/src/lib/message/message.component.ts
@@ -115,7 +115,7 @@ export class MessageComponent
private isViewInited = false;
private userId?: string;
private readonly urlRegexp =
- /(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])/gim;
+ /(?:(?:https?|ftp|file):\/\/|www\.|ftp\.|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(?![^\s]*@[^\s]*)(?:[^\s()<>]+|\([\w\d]+\))*(?
- this.messageService.customLinkRenderer
- ? this.messageService.customLinkRenderer(match)
- : `${match}`
- );
+ content = content.replace(this.urlRegexp, (match) => {
+ if (this.messageService.customLinkRenderer) {
+ return this.messageService.customLinkRenderer(match);
+ } else {
+ let href = match;
+ if (
+ !href.startsWith('http') &&
+ !href.startsWith('ftp') &&
+ !href.startsWith('file')
+ ) {
+ href = `https://${match}`;
+ }
+ return `${match}`;
+ }
+ });
return content;
}