This repository has no description
0

Configure Feed

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

fix: resolve URL parsing failures in jsdom where window.location.origin is null

+13 -13
+13 -13
src/webapp/lib/utils/link.ts
··· 32 32 }; 33 33 34 34 const isSembleUrl = (url: string): boolean => { 35 + // Relative paths are always local to the app 36 + if (url.startsWith('/')) return true; 35 37 try { 36 - const parsedUrl = new URL(url, window.location.origin); 38 + const parsedUrl = new URL(url); 37 39 return parsedUrl.origin === getAppOrigin(); 38 40 } catch { 39 41 return false; ··· 42 44 43 45 export const isCollectionPage = (url: string) => { 44 46 try { 45 - const parsedUrl = new URL(url, window.location.origin); 46 - // Must be a relative path or our own domain 47 - if (!isSembleUrl(parsedUrl.href)) return false; 47 + if (!isSembleUrl(url)) return false; 48 + const pathname = url.startsWith('/') ? url : new URL(url).pathname; 48 49 // expect /profile/:handle/collections/:id 49 50 const pattern = /^\/profile\/[^/]+\/collections\/[^/]+\/?$/; 50 - return pattern.test(parsedUrl.pathname); 51 + return pattern.test(pathname); 51 52 } catch { 52 53 // invalid URL 53 54 return false; ··· 56 57 57 58 export const isProfilePage = (url: string) => { 58 59 try { 59 - const parsedUrl = new URL(url, window.location.origin); 60 - // Must be a relative path or our own domain 61 - if (!isSembleUrl(parsedUrl.href)) return false; 60 + if (!isSembleUrl(url)) return false; 61 + const pathname = url.startsWith('/') ? url : new URL(url).pathname; 62 62 // matches /profile/:handle and any subroutes (e.g. /profile/:handle/likes) 63 63 const pattern = /^\/profile\/[^/]+/; 64 - return pattern.test(parsedUrl.pathname); 64 + return pattern.test(pathname); 65 65 } catch { 66 66 // invalid URL 67 67 return false; ··· 106 106 export const detectUrlPlatform = (url: string): PlatformData => { 107 107 if (isCollectionPage(url)) { 108 108 try { 109 - const parsedUrl = new URL(url, window.location.origin); 110 - const pathParts = parsedUrl.pathname.split('/').filter(Boolean); 109 + const pathname = url.startsWith('/') ? url : new URL(url).pathname; 110 + const pathParts = pathname.split('/').filter(Boolean); 111 111 // expected format: profile/:handle/collections/:rkey 112 112 const handle = pathParts[1]; 113 113 const rkey = pathParts[3]; ··· 124 124 125 125 if (isProfilePage(url)) { 126 126 try { 127 - const parsedUrl = new URL(url, window.location.origin); 128 - const pathParts = parsedUrl.pathname.split('/').filter(Boolean); 127 + const pathname = url.startsWith('/') ? url : new URL(url).pathname; 128 + const pathParts = pathname.split('/').filter(Boolean); 129 129 // expected format: profile/:handle or profile/:handle/:subroute 130 130 const handle = pathParts[1]; 131 131 return { type: SupportedPlatform.SEMBLE_PROFILE, url, handle };