From de6d39cedeb4af0e54ca04583ad3fe33e2ef094a Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 14 Dec 2019 09:16:31 -1000 Subject: Sanitize strings Calling String on an object with a toString property would throw an error --- lib/util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/util.js') diff --git a/lib/util.js b/lib/util.js index 731cc82..c5584ee 100644 --- a/lib/util.js +++ b/lib/util.js @@ -93,6 +93,16 @@ u.toLinkArray = function (x) { return u.toArray(x).map(u.toLink).filter(u.linkDest) } +u.toString = function (str) { + switch (typeof str) { + case 'string': return str + case 'object': + if (str !== null) return JSON.stringify(str) + default: + return String(str) + } +} + u.renderError = function(err) { return h('div.error', h('h3', err.name), -- cgit v1.2.3