From 1af7b536a58e5588ae770427e82358633f62ac03 Mon Sep 17 00:00:00 2001 From: Haocen Xu Date: Wed, 14 Aug 2019 00:02:25 -0400 Subject: [PATCH] Fix an edge case where we cannot find any shortUrl --- js/privatebin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/privatebin.js b/js/privatebin.js index d920705..b8e63dd 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1730,7 +1730,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { } 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 shortUrl = (responseString.match(shortUrlMatcher) || []).sort(function(a, b) { return a.length - b.length; })[0]; if (typeof shortUrl === 'string' && shortUrl.length > 0) {