Skip to content

Commit 9c3482f

Browse files
Merge pull request #1037 from GetStream/vishal/text-url-parsing-fix
fix: crash on parsing urls [CRNS-498]
2 parents 7b68aa7 + ee12aab commit 9c3482f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

package/src/components/Message/MessageSimple/utils/renderText.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ const parse: ParseFunction = (capture, parse, state) => ({
7070
content: parseInline(parse, capture[0], state),
7171
});
7272

73+
const parseUrlsFromText = (text: string) => {
74+
try {
75+
return anchorme(text, {
76+
list: true,
77+
});
78+
} catch (e) {
79+
console.warn(`failure at parseUrlsFromText: ${e}`);
80+
// In case of failures its not worth crashing the app,
81+
// and instead simply to have un-parsed urls in message text.
82+
return [];
83+
}
84+
};
85+
7386
export type MarkdownRules = Partial<DefaultRules>;
7487

7588
export type RenderTextParams<
@@ -125,9 +138,7 @@ export const renderText = <
125138
if (!text) return null;
126139

127140
let newText = text.trim();
128-
const urls = anchorme(newText, {
129-
list: true,
130-
});
141+
const urls = parseUrlsFromText(newText);
131142

132143
for (const urlInfo of urls) {
133144
const displayLink = truncate(urlInfo.encoded.replace(/^(www\.)/, ''), {

0 commit comments

Comments
 (0)