this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Guard against invalid URLs

+28 -17
+9 -7
src/components/link.jsx
··· 22 22 23 23 // Handle encodeURIComponent of searchParams values 24 24 if (!!hash && hash !== '/' && hash.includes('?')) { 25 - const parsedHash = new URL(hash, location.origin); // Fake base URL 26 - if (parsedHash.searchParams.size) { 27 - const searchParamsStr = Array.from(parsedHash.searchParams.entries()) 28 - .map(([key, value]) => `${key}=${encodeURIComponent(value)}`) 29 - .join('&'); 30 - hash = parsedHash.pathname + '?' + searchParamsStr; 31 - } 25 + try { 26 + const parsedHash = new URL(hash, location.origin); // Fake base URL 27 + if (parsedHash.searchParams.size) { 28 + const searchParamsStr = Array.from(parsedHash.searchParams.entries()) 29 + .map(([key, value]) => `${key}=${encodeURIComponent(value)}`) 30 + .join('&'); 31 + hash = parsedHash.pathname + '?' + searchParamsStr; 32 + } 33 + } catch (e) {} 32 34 } 33 35 34 36 const isActive = hash === to || decodeURIComponent(hash) === to;
+6 -1
src/components/status.jsx
··· 2269 2269 theURL = `https://${finalURL}`; 2270 2270 } 2271 2271 2272 - const urlObj = new URL(theURL); 2272 + let urlObj; 2273 + try { 2274 + urlObj = new URL(theURL); 2275 + } catch (e) { 2276 + return; 2277 + } 2273 2278 const domain = urlObj.hostname; 2274 2279 const path = urlObj.pathname; 2275 2280 // Regex /:username/:id, where username = @username or @username@domain, id = number
+13 -9
src/utils/isMastodonLinkMaybe.jsx
··· 1 1 export default function isMastodonLinkMaybe(url) { 2 - const { pathname, hash } = new URL(url); 3 - return ( 4 - /^\/.*\/\d+$/i.test(pathname) || 5 - /^\/@[^/]+\/(statuses|posts)\/\w+\/?$/i.test(pathname) || // GoToSocial, Takahe 6 - /^\/notes\/[a-z0-9]+$/i.test(pathname) || // Misskey, Firefish 7 - /^\/notes\/[a-z0-9]+$/i.test(pathname) || // Misskey, Calckey 8 - /^\/(notice|objects)\/[a-z0-9-]+$/i.test(pathname) || // Pleroma 9 - /#\/[^\/]+\.[^\/]+\/s\/.+/i.test(hash) // Phanpy 🫣 10 - ); 2 + try { 3 + const { pathname, hash } = new URL(url); 4 + return ( 5 + /^\/.*\/\d+$/i.test(pathname) || 6 + /^\/@[^/]+\/(statuses|posts)\/\w+\/?$/i.test(pathname) || // GoToSocial, Takahe 7 + /^\/notes\/[a-z0-9]+$/i.test(pathname) || // Misskey, Firefish 8 + /^\/notes\/[a-z0-9]+$/i.test(pathname) || // Misskey, Calckey 9 + /^\/(notice|objects)\/[a-z0-9-]+$/i.test(pathname) || // Pleroma 10 + /#\/[^\/]+\.[^\/]+\/s\/.+/i.test(hash) // Phanpy 🫣 11 + ); 12 + } catch (e) { 13 + return false; 14 + } 11 15 }