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 <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2021-12-09 16:25:50 +01:00
parent 4381816315
commit 008bd89310

View file

@ -521,9 +521,14 @@ String.prototype.format = function()
var quot_esc = [/"/g, '&#34;', /'/g, '&#39;'];
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]);