Skip to content

Commit 52bf679

Browse files
authored
Merge pull request #683 from GetStream/fix-url-regexp
fix: imrpoved url regexp was failing on iOS 16.4 and older #612
2 parents 31c35ea + 7092f18 commit 52bf679

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

projects/stream-chat-angular/src/lib/message-text/message-text.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,23 @@ export class MessageTextComponent implements OnChanges {
4242
messageTextParts: MessagePart[] | undefined = [];
4343
messageText?: string;
4444
displayAs: 'text' | 'html';
45-
private readonly urlRegexp =
46-
/(?:(?:https?|ftp|file):\/\/|www\.|ftp\.|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(?![^\s]*@[^\s]*)(?:[^\s()<>]+|\([\w\d]+\))*(?<!@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/gim;
45+
private readonly urlRegexp: RegExp;
4746
private emojiRegexp = new RegExp(emojiRegex(), 'g');
4847

4948
constructor(
5049
private messageService: MessageService,
5150
readonly customTemplatesService: CustomTemplatesService
5251
) {
5352
this.displayAs = this.messageService.displayAs;
53+
try {
54+
this.urlRegexp = new RegExp(
55+
'(?:(?:https?|ftp|file):\\/\\/|www\\.|ftp\\.|(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,})(?![^\\s]*@[^\\s]*)(?:[^\\s()<>]+|\\([\\w\\d]+\\))*(?<!@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})',
56+
'gim'
57+
);
58+
} catch {
59+
this.urlRegexp =
60+
/(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])/gim;
61+
}
5462
}
5563

5664
ngOnChanges(changes: SimpleChanges): void {

0 commit comments

Comments
 (0)