aboutsummaryrefslogtreecommitdiff
path: root/lib/util.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-12-14 09:16:31 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-12-14 09:16:31 -1000
commitde6d39cedeb4af0e54ca04583ad3fe33e2ef094a (patch)
treed28125d512c6fc331fa1fedc9efad0c5aecc9710 /lib/util.js
parent0bd830cf4ebf9cf3e4df1f2dba4b851b9361fc14 (diff)
downloadpatchfoo-de6d39cedeb4af0e54ca04583ad3fe33e2ef094a.tar.gz
patchfoo-de6d39cedeb4af0e54ca04583ad3fe33e2ef094a.zip
Sanitize strings
Calling String on an object with a toString property would throw an error
Diffstat (limited to 'lib/util.js')
-rw-r--r--lib/util.js10
1 files changed, 10 insertions, 0 deletions
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),