]> cat aescling's git repositories - mastodon.git/commitdiff
Remove href attribute of invalid links instead of crashing
authorThibaut Girka <thib@sitedethib.com>
Tue, 6 Aug 2019 09:31:28 +0000 (11:31 +0200)
committerThibG <thib@sitedethib.com>
Tue, 6 Aug 2019 10:32:06 +0000 (12:32 +0200)
app/javascript/flavours/glitch/components/status_content.js

index a7e17d252afa64060fe3719ba16e63af8e7bf5eb..20e640bcb638204baaa457d9cf7dd9487ae51017 100644 (file)
@@ -106,14 +106,19 @@ export default class StatusContent extends React.PureComponent {
         link.setAttribute('title', link.href);
         link.classList.add('unhandled-link');
 
-        if (tagLinks && isLinkMisleading(link)) {
-          // Add a tag besides the link to display its origin
-
-          const tag = document.createElement('span');
-          tag.classList.add('link-origin-tag');
-          tag.textContent = `[${new URL(link.href).host}]`;
-          link.insertAdjacentText('beforeend', ' ');
-          link.insertAdjacentElement('beforeend', tag);
+        try {
+          if (tagLinks && isLinkMisleading(link)) {
+            // Add a tag besides the link to display its origin
+
+            const tag = document.createElement('span');
+            tag.classList.add('link-origin-tag');
+            tag.textContent = `[${new URL(link.href).host}]`;
+            link.insertAdjacentText('beforeend', ' ');
+            link.insertAdjacentElement('beforeend', tag);
+          }
+        } catch (TypeError) {
+          // Just to be safe
+          if (tagLinks) link.removeAttribute('href');
         }
       }