mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-22 07:46:17 -04:00
Merge branch 'schlagmichdoch:master' into master
This commit is contained in:
commit
829cc7c43b
12 changed files with 160 additions and 116 deletions
|
@ -2021,8 +2021,8 @@ class ReceiveTextDialog extends Dialog {
|
|||
if (text.length < 2000) {
|
||||
// replace URLs with actual links
|
||||
this.$text.innerHTML = this.$text.innerHTML
|
||||
.replace(/(^|(?<=(<br>|\s)))(https?:\/\/|www.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%]){2,}\.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%.]){2,})/g,
|
||||
(url) => {
|
||||
.replace(/(^|<br>|\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
|
||||
|
@ -2030,7 +2030,13 @@ class ReceiveTextDialog extends Dialog {
|
|||
link = "http://" + link
|
||||
}
|
||||
|
||||
return `<a href="${link}" target="_blank">${url}</a>`;
|
||||
// Check if link is valid
|
||||
if (isUrlValid(link)) {
|
||||
return `${whitespace}<a href="${link}" target="_blank">${url}</a>`;
|
||||
}
|
||||
else {
|
||||
return match;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue