From 6867e9bed4f7cf9c211e5efeaa0b6f116a35c688 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Tue, 30 Jun 2015 13:56:27 +0100 Subject: [PATCH] Check whether there are any URLs before iterating over them. MAY fix a problem in the test-suite. Thanks for Wolfram for spotting this. --- src/mkws-widget-main.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index f1b13e0..b218a95 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -140,20 +140,22 @@ mkws.registerWidgetType('records', function() { } var urls = hit['md-electronic-url']; - var bestLink = null; - var otherLinks = []; - for (var j = 0; j < urls.length; j++) { - var url = urls[j]; - if (!url.match(/^(https?:)?\/\//)) { - that.warn("link '" + url + "' is not a valid URL"); - } else if (!bestLink) { - bestLink = url; - } else { - otherLinks.push(url); + if (urls) { + var bestLink = null; + var otherLinks = []; + for (var j = 0; j < urls.length; j++) { + var url = urls[j]; + if (!url.match(/^(https?:)?\/\//)) { + that.warn("link '" + url + "' is not a valid URL"); + } else if (!bestLink) { + bestLink = url; + } else { + otherLinks.push(url); + } } + hit.bestLink = bestLink; + hit.otherLinks = otherLinks; } - hit.bestLink = bestLink; - hit.otherLinks = otherLinks; } var template = team.loadTemplate(that.config.template || "records"); -- 1.7.10.4