Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Custom exercises: a link needs a real host, so "not a url" is no longer saved as one
Duarte Santos4aea9b2b30a7
diff --git a/frontend/src/lib/media-refs.js b/frontend/src/lib/media-refs.jsindex bc06547eb..2658ffac7 100644--- a/frontend/src/lib/media-refs.js+++ b/frontend/src/lib/media-refs.js@@ -188,13 +188,30 @@ export function cleanUrl(raw) {if (/^[a-z0-9+.-]+:/i.test(s)) return nulls = 'https://' + s}+ // Chrome's URL parser takes "https://not a url" and percent-encodes the spaces into the host,+ // so "not a url" typed into the link field was saved as a link (QA 1.3.9). The host has to+ // be one a browser could reach: no whitespace in what was typed, and a dotted name,+ // localhost or an IP address.+ const authority = /^https?:\/\/([^/?#]*)/i.exec(s)?.[1] || ''+ if (/\s/.test(authority)) return nulllet utry { u = new URL(s) } catch { return null }if (u.protocol !== 'http:' && u.protocol !== 'https:') return nullif (!u.hostname || u.username || u.password) return null+ if (!plausibleHost(u.hostname)) return nullreturn u.href.length <= MAX_URL ? u.href : null}+const LABEL = /^(?!-)[a-z0-9-]{1,63}(?<!-)$/i+function plausibleHost(host) {+ if (host.startsWith('[') && host.endsWith(']')) return true // IPv6+ const h = host.replace(/\.$/, '').toLowerCase()+ if (h === 'localhost') return true+ const labels = h.split('.')+ // xn-- names are how the parser writes an international domain, so they pass as letters.+ return labels.length >= 2 && labels.every(l => LABEL.test(l))+}+// Hosts whose pages are, in practice, a video: the card then says "Watch video" instead of// "Open link". Only the wording changes — nothing is fetched or embedded either way.const VIDEO_HOSTS = ['youtube.com', 'youtu.be', 'vimeo.com', 'tiktok.com', 'instagram.com']diff --git a/frontend/src/lib/media-refs.test.js b/frontend/src/lib/media-refs.test.jsindex b4fb61958..137327718 100644--- a/frontend/src/lib/media-refs.test.js+++ b/frontend/src/lib/media-refs.test.js@@ -117,6 +117,18 @@ describe('cleanUrl', () => {expect(cleanUrl('https://exa mple.com')).toBeNull()expect(cleanUrl('https://')).toBeNull()})+ // QA 1.3.9: Chrome parses "https://not a url" (the spaces go into the host as %20), so a+ // sentence typed into the link field was saved as a link.+ it('wants a host a browser could reach: no spaces, a dotted name, localhost or an IP', () => {+ for (const u of ['not a url', 'https://not a url', 'hello', 'https://hello', 'http://a..b', 'https://-x.com', 'https://x%20y.com']) {+ expect(cleanUrl(u), u).toBeNull()+ }+ expect(cleanUrl('http://localhost:8080/x')).toBe('http://localhost:8080/x')+ expect(cleanUrl('http://192.168.1.10/guide')).toBe('http://192.168.1.10/guide')+ expect(cleanUrl('http://[::1]:3000/')).toBe('http://[::1]:3000/')+ expect(cleanUrl('https://müller.de/x')).toBe('https://xn--mller-kva.de/x')+ expect(cleanUrl('example.com./x')).toBe('https://example.com./x')+ })})describe('linkKind', () => {