about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/components
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-08-06 11:31:28 +0200
committerThibG <thib@sitedethib.com>2019-08-06 12:32:06 +0200
commitcbd75fe1284f67c941967f20ab9fef508ed70e1c (patch)
tree89c60e174c0bf8248a8bbcd28ee66661f66b8d29 /app/javascript/flavours/glitch/components
parent0aee74d78a801285ac33647791da9cb1ede9ddf4 (diff)
Remove href attribute of invalid links instead of crashing
Diffstat (limited to 'app/javascript/flavours/glitch/components')
-rw-r--r--app/javascript/flavours/glitch/components/status_content.js21
1 files changed, 13 insertions, 8 deletions
diff --git a/app/javascript/flavours/glitch/components/status_content.js b/app/javascript/flavours/glitch/components/status_content.js
index a7e17d252..20e640bcb 100644
--- a/app/javascript/flavours/glitch/components/status_content.js
+++ b/app/javascript/flavours/glitch/components/status_content.js
@@ -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');
         }
       }