From 62f843b4dcc3c651be016675ac4d0ea30a44b506 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 17 May 2024 17:10:54 +0800 Subject: [PATCH] Fix crash when media url doesn't have http prefix --- src/components/media.jsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/media.jsx b/src/components/media.jsx index ce2f13ac..727bcb06 100644 --- a/src/components/media.jsx +++ b/src/components/media.jsx @@ -166,7 +166,7 @@ function Media({ [to], ); - const remoteMediaURLObj = remoteMediaURL ? new URL(remoteMediaURL) : null; + const remoteMediaURLObj = remoteMediaURL ? getURLObj(remoteMediaURL) : null; const isVideoMaybe = type === 'unknown' && remoteMediaURLObj && @@ -618,4 +618,13 @@ function Media({ } } +function getURLObj(url) { + try { + // Fake base URL if url doesn't have https:// prefix + return new URL(url, location.origin); + } catch (e) { + return null; + } +} + export default Media;