about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorSteven <steven@ceriously.com>2023-07-27 11:49:37 -0400
committerGitHub <noreply@github.com>2023-07-27 10:49:37 -0500
commit5a0899b989769dc3417096ae2d040cd768f4524c (patch)
tree3de8a486b3f58772483e21b31212afaab6fe8961 /src/lib
parent44b3929240736ead1740efa791e9f4aaf792f2f4 (diff)
downloadvoidsky-5a0899b989769dc3417096ae2d040cd768f4524c.tar.zst
fix: invisible url when only a protocol (#1059)
* fix: invisible url when only a protocol

- Fixes https://github.com/bluesky-social/social-app/issues/1058

* fix: handle more cases when url is not http/https
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/strings/url-helpers.ts5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts
index ec1292e94..105c631bf 100644
--- a/src/lib/strings/url-helpers.ts
+++ b/src/lib/strings/url-helpers.ts
@@ -39,6 +39,9 @@ export function toNiceDomain(url: string): string {
 export function toShortUrl(url: string): string {
   try {
     const urlp = new URL(url)
+    if (urlp.protocol !== 'http:' && urlp.protocol !== 'https:') {
+      return url
+    }
     const shortened =
       urlp.host +
       (urlp.pathname === '/' ? '' : urlp.pathname) +
@@ -47,7 +50,7 @@ export function toShortUrl(url: string): string {
     if (shortened.length > 30) {
       return shortened.slice(0, 27) + '...'
     }
-    return shortened
+    return shortened ? shortened : url
   } catch (e) {
     return url
   }