Skip to content

Commit 6178513

Browse files
committed
fix(renderText): recognize uppercase URL schemes in message links
1 parent b9ef6cd commit 6178513

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/components/Message/renderText/__tests__/renderText.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ describe(`renderText`, () => {
2828
expect(container).toMatchSnapshot();
2929
});
3030

31+
it('linkifies a URL with an uppercase scheme like a lowercase one', () => {
32+
const Markdown = renderText('see HTTPS://en.wikipedia.org/wiki/Apple');
33+
render(Markdown);
34+
const link = screen.getByRole('link', { name: 'en.wikipedia.org/wiki/Apple' });
35+
expect(link).toHaveClass('str-chat__message-url-link');
36+
expect(link).toHaveAttribute('href', 'HTTPS://en.wikipedia.org/wiki/Apple');
37+
});
38+
3139
it('handles the special case where user name matches to an e-mail pattern - 1', () => {
3240
const Markdown = renderText(
3341
'Hello @username@email.com, is username@email.com your @primary e-mail?',

src/components/Message/renderText/componentRenderers/Anchor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44

55
export const Anchor = ({ children, href }: ComponentProps<'a'>) => {
66
const isEmail = href?.startsWith('mailto:');
7-
const isUrl = href?.startsWith('http');
7+
const isUrl = href?.toLowerCase().startsWith('http');
88

99
if (!href || (!isEmail && !isUrl)) return <>{children}</>;
1010

src/components/Message/renderText/regex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export function escapeRegExp(text: string) {
22
return text.replace(/[-[\]{}()*+?.,/\\^$|#]/g, '\\$&');
33
}
44

5-
export const detectHttp = /(http(s?):\/\/)?(www\.)?/;
5+
export const detectHttp = /(http(s?):\/\/)?(www\.)?/i;
66

77
// Regexes are hoisted to module scope so they are compiled once rather than on
88
// every call. `codeRegex`/`regexMdLinks` are only used with `String#match`

0 commit comments

Comments
 (0)