Преглед изворни кода

Add http prefix to listed golinks to not make them point to go/go/...

Taddeus Kroes пре 6 дана
родитељ
комит
7df9b12dcb
1 измењених фајлова са 5 додато и 1 уклоњено
  1. 5 1
      ui/src/LinksPage/LinksView/ShortLink/ShortLink.tsx

+ 5 - 1
ui/src/LinksPage/LinksView/ShortLink/ShortLink.tsx

@@ -7,11 +7,15 @@ export interface ShortLinkProps {
 export const ShortLink = ({ url }: ShortLinkProps) => {
   return (
     <div className={css.shortlink}>
-      <a href={url}>{stripScheme(url)}</a>
+      <a href={ensureHttp(url)}>{stripScheme(url)}</a>
     </div>
   );
 };
 
+function ensureHttp(url: string): string {
+  return url.startsWith('http') ? url : `http://${url}`;
+}
+
 function stripScheme(url: string): string {
   return url.replace(/^https?:\/\//, "");
 }