Skip to content

Commit

Permalink
Fix bad YouTube links breaking chat (#390)
Browse files Browse the repository at this point in the history
* fix: ignore url errors while trying to normalize yt links

* fix: make youtube url regex stricter
  • Loading branch information
vyneer authored Dec 31, 2023
1 parent 57369b9 commit 67fa2d4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions assets/chat/js/formatters/UrlFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ export default class UrlFormatter {
return url.split('?')[0];
}

if (/youtu(?:be\.com|\.be)/i.test(url)) {
if (/^(?:(?:https|http):\/\/)?(?:www\.)?youtu(?:be\.com|\.be)/i.test(url)) {
// Same as with xeets, remove the nasty share tracking query param
// from YouTube links.
const ytLink = new URL(url);
ytLink.searchParams.delete('si');
return ytLink.href;
try {
const ytLink = new URL(url);
ytLink.searchParams.delete('si');
return ytLink.href;
} catch {
return url;
}
}

return url;
Expand Down

0 comments on commit 67fa2d4

Please sign in to comment.