From cc0b6e387ab6e4924d8539800a8a98ebff4ca318 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 4 Jan 2024 23:23:47 +0100 Subject: [PATCH] avoid use of bleeding edge function only supported in Firefox & Chrome >= 120 & node >= 19.9.0 & 18.17.0 --- js/privatebin.js | 6 +++++- js/test/PasteStatus.js | 7 ------- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index e63ab5fb..930a1315 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -2119,7 +2119,11 @@ jQuery.PrivateBin = (function($, RawDeflate) { if (typeof response === 'string' && response.length > 0) { const shortUrlMatcher = /https?:\/\/[^\s]+/g; const shortUrl = (response.match(shortUrlMatcher) || []).filter(function(a) { - return URL.canParse(a); + try { + return !!new URL(a); + } catch (error) { + return false; + } }).sort(function(a, b) { return a.length - b.length; })[0]; diff --git a/js/test/PasteStatus.js b/js/test/PasteStatus.js index 9a5c60d0..baa6ab33 100644 --- a/js/test/PasteStatus.js +++ b/js/test/PasteStatus.js @@ -56,13 +56,6 @@ describe('PasteStatus', function () { ('#' + encodeURI(fragment)) : ''), clean = jsdom(); - // not available in node before v19.9.0, v18.17.0 - if (typeof URL.canParse !== 'function') { - URL.canParse = function(a) { - return true; - } - } - $('body').html('
'); $.PrivateBin.PasteStatus.init(); $.PrivateBin.PasteStatus.createPasteNotification('', ''); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 3c72c00b..927891ac 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 c66c2ee5..ba08d2ef 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -51,7 +51,7 @@ endif; ?> - +