From 0d6ff2535e4af3b16f7c60c71f93bd645e8a3668 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sun, 1 Oct 2017 13:23:40 +0000 Subject: [PATCH 1/2] fix(package): update urijs to version 1.19.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f5740b1a..86636fe9 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "socket.io": "1.7.4", "spdy": "3.4.7", "ua-parser-js": "0.7.14", - "urijs": "1.18.12", + "urijs": "1.19.0", "web-push": "3.2.3" }, "devDependencies": { From 9a8c1b2fd00db60d66684856f6987cf54e503796 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 5 Oct 2017 23:44:20 +0300 Subject: [PATCH 2/2] Wrap withinString in try/catch --- .../handlebars/ircmessageparser/findLinks.js | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/client/js/libs/handlebars/ircmessageparser/findLinks.js b/client/js/libs/handlebars/ircmessageparser/findLinks.js index 50c442e6..803ddb1d 100644 --- a/client/js/libs/handlebars/ircmessageparser/findLinks.js +++ b/client/js/libs/handlebars/ircmessageparser/findLinks.js @@ -22,41 +22,45 @@ function findLinks(text) { // -Tags. // See https://medialize.github.io/URI.js/docs.html#static-withinString // In our case, we store each URI encountered in a result array. - URI.withinString(text, function(url, start, end) { - let parsedScheme; + try { + URI.withinString(text, function(url, start, end) { + let parsedScheme; - try { - // Extract the scheme of the URL detected, if there is one - parsedScheme = URI(url).scheme().toLowerCase(); - } catch (e) { - // URI may throw an exception for malformed urls, - // as to why withinString finds these in the first place is a mystery - return; - } + try { + // Extract the scheme of the URL detected, if there is one + parsedScheme = URI(url).scheme().toLowerCase(); + } catch (e) { + // URI may throw an exception for malformed urls, + // as to why withinString finds these in the first place is a mystery + return; + } - // Check if the scheme of the detected URL matches a common one above. - // In a URL like `foo..http://example.com`, the scheme would be `foo..http`, - // so we need to clean up the end of the scheme and filter out the rest. - const matchedScheme = commonSchemes.find((scheme) => parsedScheme.endsWith(scheme)); + // Check if the scheme of the detected URL matches a common one above. + // In a URL like `foo..http://example.com`, the scheme would be `foo..http`, + // so we need to clean up the end of the scheme and filter out the rest. + const matchedScheme = commonSchemes.find((scheme) => parsedScheme.endsWith(scheme)); - // A known scheme was found, extract the unknown part from the URL - if (matchedScheme) { - const prefix = parsedScheme.length - matchedScheme.length; - start += prefix; - url = url.slice(prefix); - } + // A known scheme was found, extract the unknown part from the URL + if (matchedScheme) { + const prefix = parsedScheme.length - matchedScheme.length; + start += prefix; + url = url.slice(prefix); + } - // The URL matched but does not start with a scheme (`www.foo.com`), add it - if (!parsedScheme.length) { - url = "http://" + url; - } + // The URL matched but does not start with a scheme (`www.foo.com`), add it + if (!parsedScheme.length) { + url = "http://" + url; + } - result.push({ - start: start, - end: end, - link: url + result.push({ + start: start, + end: end, + link: url + }); }); - }); + } catch (e) { + // withinString is wrapped in a try/catch due to https://github.com/medialize/URI.js/issues/359 + } return result; }