diff --git a/public/scripts/ui.js b/public/scripts/ui.js
index 1917eb8..e399d89 100644
--- a/public/scripts/ui.js
+++ b/public/scripts/ui.js
@@ -2019,8 +2019,8 @@ class ReceiveTextDialog extends Dialog {
if (text.length < 2000) {
// replace URLs with actual links
this.$text.innerHTML = this.$text.innerHTML
- .replace(/(^|(?<=(
|\s)))(https?:\/\/|www.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%]){2,}\.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%.]){2,})/g,
- (url) => {
+ .replace(/(^|
|\s|")((https?:\/\/|www.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%]){2,}\.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%.]){2,}))/g,
+ (match, whitespace, url) => {
let link = url;
// prefix www.example.com with http protocol to prevent it from being a relative link
@@ -2028,7 +2028,13 @@ class ReceiveTextDialog extends Dialog {
link = "http://" + link
}
- return `${url}`;
+ // Check if link is valid
+ if (isUrlValid(link)) {
+ return `${whitespace}${url}`;
+ }
+ else {
+ return match;
+ }
});
}
diff --git a/public/scripts/util.js b/public/scripts/util.js
index 1ab43c5..fc418ff 100644
--- a/public/scripts/util.js
+++ b/public/scripts/util.js
@@ -583,4 +583,14 @@ async function decodeBase64Text(base64) {
if (!base64) throw new Error('Base64 is empty');
return decodeURIComponent(escape(window.atob(base64)))
+}
+
+function isUrlValid(url) {
+ try {
+ let urlObj = new URL(url);
+ return true;
+ }
+ catch (e) {
+ return false;
+ }
}
\ No newline at end of file