From 7cb1f8ca67c1422e0609f6912007f57557a2c7b4 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 4 Jan 2024 06:48:34 +0100 Subject: [PATCH] relax URL regex to support finding IDN domains, filter using built in function, removing non-URLs --- js/privatebin.js | 4 ++-- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index c5ee7fb0..db85eef7 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -2041,8 +2041,8 @@ jQuery.PrivateBin = (function($, RawDeflate) { responseString = JSON.stringify(responseString); } if (typeof responseString === 'string' && responseString.length > 0) { - const shortUrlMatcher = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g; - const shortUrl = (responseString.match(shortUrlMatcher) || []).sort(function(a, b) { + const shortUrlMatcher = /https?:\/\/[^\s]+/g; + const shortUrl = (responseString.match(shortUrlMatcher) || []).filter(URL.canParse).sort(function(a, b) { return a.length - b.length; })[0]; if (typeof shortUrl === 'string' && shortUrl.length > 0) { diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index a307c4e7..386705fa 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -73,7 +73,7 @@ endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index fa70097a..026b4ae1 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -51,7 +51,7 @@ endif; ?> - +