瀏覽代碼

Fixes #2718: Message is not displayed if it contains an invalid URL

JC Brand 3 年之前
父節點
當前提交
ee4e056125
共有 2 個文件被更改,包括 10 次插入2 次删除
  1. 1 0
      CHANGES.md
  2. 9 2
      src/templates/hyperlink.js

+ 1 - 0
CHANGES.md

@@ -14,6 +14,7 @@
 - #2423: Could not find dependency "converse-controlbox" for plugin "converse-muc"
 - #2647: Singleton mode doesn't work
 - #2704: Send button doesn't work in a multi-user chat
+- #2718: Message is not displayed if it contains an invalid URL
 - #2725: Send new presence status to all connected MUCs
 - #2728: Not sending headers with upload request
 - #2733: OMEMO Messages received while client closed not decrypted

+ 9 - 2
src/templates/hyperlink.js

@@ -1,5 +1,6 @@
-import { html } from "lit";
+import log from '@converse/headless/log';
 import { api } from  "@converse/headless/core";
+import { html } from "lit";
 
 function onClickXMPPURI (ev) {
     ev.preventDefault();
@@ -7,7 +8,13 @@ function onClickXMPPURI (ev) {
 }
 
 export default (uri, url_text) => {
-    let normalized_url = uri.normalize()._string;
+    let normalized_url;
+    try {
+        normalized_url = uri.normalize()._string;
+    } catch (e) {
+        log.error(e);
+        return url_text;
+    }
     const pretty_url = uri._parts.urn ? normalized_url : uri.readable();
     const visible_url = url_text || pretty_url;
     if (!uri._parts.protocol && !normalized_url.startsWith('http://') && !normalized_url.startsWith('https://')) {