Skip to content

Commit

Permalink
Fix crash when media url doesn't have http prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed May 17, 2024
1 parent b0a53b7 commit 62f843b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/media.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;

0 comments on commit 62f843b

Please sign in to comment.