mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 15:06:15 -04:00
Fix Error Invalid Group Specifier Name on Safari by removing REGEX lookbehind group construct (fixes #239)
This commit is contained in:
parent
041261be2a
commit
2e15a018da
2 changed files with 19 additions and 3 deletions
|
@ -2019,8 +2019,8 @@ class ReceiveTextDialog extends Dialog {
|
||||||
if (text.length < 2000) {
|
if (text.length < 2000) {
|
||||||
// replace URLs with actual links
|
// replace URLs with actual links
|
||||||
this.$text.innerHTML = this.$text.innerHTML
|
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,
|
.replace(/(^|<br>|\s|")((https?:\/\/|www.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%]){2,}\.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%.]){2,}))/g,
|
||||||
(url) => {
|
(match, whitespace, url) => {
|
||||||
let link = url;
|
let link = url;
|
||||||
|
|
||||||
// prefix www.example.com with http protocol to prevent it from being a relative link
|
// 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
|
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');
|
if (!base64) throw new Error('Base64 is empty');
|
||||||
|
|
||||||
return decodeURIComponent(escape(window.atob(base64)))
|
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