From 008bd893105d2bc8bfb5e5dce1ef00fa09008533 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 9 Dec 2021 16:25:50 +0100 Subject: [PATCH] luci-base: cbi.js: properly handle non-strings in `%h` and `%q` formats Only replace null, objects and function values with the empty string but return booleans and numbers as strings. Spotted while debugging #5587. Signed-off-by: Jo-Philipp Wich --- modules/luci-base/htdocs/luci-static/resources/cbi.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 9200954d1e..324a91403f 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -521,9 +521,14 @@ String.prototype.format = function() var quot_esc = [/"/g, '"', /'/g, ''']; function esc(s, r) { - if (typeof(s) !== 'string' && !(s instanceof String)) + var t = typeof(s); + + if (s == null || t === 'object' || t === 'function') return ''; + if (t !== 'string') + s = String(s); + for (var i = 0; i < r.length; i += 2) s = s.replace(r[i], r[i+1]);