Skip to content

Commit

Permalink
Merge pull request #683 from GetStream/fix-url-regexp
Browse files Browse the repository at this point in the history
fix: imrpoved url regexp was failing on iOS 16.4 and older #612
  • Loading branch information
szuperaz authored Jan 20, 2025
2 parents 31c35ea + 7092f18 commit 52bf679
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@ export class MessageTextComponent implements OnChanges {
messageTextParts: MessagePart[] | undefined = [];
messageText?: string;
displayAs: 'text' | 'html';
private readonly urlRegexp =
/(?:(?: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;
private readonly urlRegexp: RegExp;
private emojiRegexp = new RegExp(emojiRegex(), 'g');

constructor(
private messageService: MessageService,
readonly customTemplatesService: CustomTemplatesService
) {
this.displayAs = this.messageService.displayAs;
try {
this.urlRegexp = new RegExp(
'(?:(?: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'
);
} catch {
this.urlRegexp =
/(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])/gim;
}
}

ngOnChanges(changes: SimpleChanges): void {
Expand Down

0 comments on commit 52bf679

Please sign in to comment.