Skip to content

Commit 4926e67

Browse files
committed
fix(message): recognize uppercase URL schemes in message links
1 parent cde2d2d commit 4926e67

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,42 @@ describe('MessageTextComponent', () => {
302302
);
303303
});
304304

305+
it('should not double-prefix URLs with uppercase or mixed-case schemes', () => {
306+
component.message = {
307+
text: 'This is a message with a link HTTPS://example.com',
308+
} as any as StreamMessage;
309+
component.ngOnChanges({ message: {} as SimpleChange });
310+
311+
expect(component.messageTextParts![0].content).toContain(
312+
'<a href="HTTPS://example.com" target="_blank" rel="nofollow">HTTPS://example.com</a>'
313+
);
314+
expect(component.messageTextParts![0].content).not.toContain(
315+
'https://HTTPS://example.com'
316+
);
317+
318+
component.message.text =
319+
'This is a message with a link Https://example.com';
320+
component.ngOnChanges({ message: {} as SimpleChange });
321+
322+
expect(component.messageTextParts![0].content).toContain(
323+
'<a href="Https://example.com" target="_blank" rel="nofollow">Https://example.com</a>'
324+
);
325+
326+
component.message.text = 'This is a message with a link FTP://example.com';
327+
component.ngOnChanges({ message: {} as SimpleChange });
328+
329+
expect(component.messageTextParts![0].content).toContain(
330+
'<a href="FTP://example.com" target="_blank" rel="nofollow">FTP://example.com</a>'
331+
);
332+
333+
component.message.text = 'This is a message with a link example.com';
334+
component.ngOnChanges({ message: {} as SimpleChange });
335+
336+
expect(component.messageTextParts![0].content).toContain(
337+
'<a href="https://example.com" target="_blank" rel="nofollow">example.com</a>'
338+
);
339+
});
340+
305341
it('should replace URL links inside text content - custom link renderer', () => {
306342
const service = TestBed.inject(MessageService);
307343
service.customLinkRenderer = (url) =>

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ export class MessageTextComponent implements OnChanges {
157157
return this.messageService.customLinkRenderer(match);
158158
} else {
159159
let href = match;
160-
if (
161-
!href.startsWith('http') &&
162-
!href.startsWith('ftp') &&
163-
!href.startsWith('file')
164-
) {
160+
if (!/^(?:https?|ftp|file):\/\//i.test(href)) {
165161
href = `https://${match}`;
166162
}
167163
return `<a href="${href}" target="_blank" rel="nofollow">${match}</a>`;

0 commit comments

Comments
 (0)