diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-10-10 14:02:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-10 14:02:50 -0700 |
commit | 4d450da1941464b19dab201202ba3e9f41d2c057 (patch) | |
tree | 2ada6a3db2d364741df128919192bef4c96f7929 /src/lib/strings/url-helpers.ts | |
parent | e878da04a1f84e1b64caf18ecf5b60ee1c583d85 (diff) | |
download | voidsky-4d450da1941464b19dab201202ba3e9f41d2c057.tar.zst |
Only warn on links to bsky.app if it represents itself as another url (#1662)
* Only warn on links to bsky.app if it represents itself as another url (close #1652) * Clean up
Diffstat (limited to 'src/lib/strings/url-helpers.ts')
-rw-r--r-- | src/lib/strings/url-helpers.ts | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts index 3c27d8639..106d2ca31 100644 --- a/src/lib/strings/url-helpers.ts +++ b/src/lib/strings/url-helpers.ts @@ -170,15 +170,32 @@ export function getYoutubeVideoId(link: string): string | undefined { export function linkRequiresWarning(uri: string, label: string) { const labelDomain = labelToDomain(label) - if (!labelDomain) { - return true - } + let urip try { - const urip = new URL(uri) - return labelDomain !== urip.hostname + urip = new URL(uri) } catch { return true } + + if (urip.hostname === 'bsky.app') { + // if this is a link to internal content, + // warn if it represents itself as a URL to another app + if ( + labelDomain && + labelDomain !== 'bsky.app' && + isPossiblyAUrl(labelDomain) + ) { + return true + } + return false + } else { + // if this is a link to external content, + // warn if the label doesnt match the target + if (!labelDomain) { + return true + } + return labelDomain !== urip.hostname + } } function labelToDomain(label: string): string | undefined { |