mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
fix(client): only give a scheme to something that looks like a host
safeExternalHref prefixed https:// to anything without a scheme, which turns a note that reads "call the hotel" into a link to a host that does not exist. A dot and no whitespace is what separates www.hotel.com from free text.
This commit is contained in:
@@ -42,5 +42,9 @@ export function safeExternalHref(value: string | null | undefined): string | nul
|
||||
if (/^https?:\/\//i.test(collapsed)) return trimmed
|
||||
// Any other scheme, executing or merely unexpected, stays unlinked.
|
||||
if (/^[a-z][a-z0-9+.-]*:/i.test(collapsed)) return null
|
||||
return `https://${trimmed}`
|
||||
// A bare host gets https://, the way an address bar would take it. Free text
|
||||
// does not: "www.hotel.com" is a site somebody meant to link, "call the hotel"
|
||||
// is a note, and turning the second into a link is worse than leaving it flat.
|
||||
if (/^[^\s/?#]+\.[^\s/?#]+/.test(trimmed)) return `https://${trimmed}`
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user