From aeb0f7cc8587c2d6abd3710daacbf4d3f705686e Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 31 Mar 2014 16:35:41 +0100 Subject: [PATCH] JSON parsing of data-mkws-config attribute now protected by try/catch block, complains loudly on failure. --- src/mkws-widgets.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mkws-widgets.js b/src/mkws-widgets.js index c2795db..c3a309d 100644 --- a/src/mkws-widgets.js +++ b/src/mkws-widgets.js @@ -27,10 +27,15 @@ function widget($, team, type, node) { if (a.name === 'data-mkws-config') { // Treat as a JSON fragment configuring just this widget log(node + ": parsing config fragment '" + a.value + "'"); - var data = $.parseJSON(a.value); - for (var key in data) { - log(node + ": adding config element " + key + "='" + data[key] + "'"); - that.config[key] = data[key]; + var data; + try { + data = $.parseJSON(a.value); + for (var key in data) { + log(node + ": adding config element " + key + "='" + data[key] + "'"); + that.config[key] = data[key]; + } + } catch (err) { + alert("Can't parse " + node + " data-mkws-config as JSON: " + a.value); } } else if (a.name.match (/^data-mkws-/)) { var name = a.name.replace(/^data-mkws-/, '') -- 1.7.10.4