diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-12-09 18:25:50 +0300 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-12-09 18:25:50 +0300 |
commit | 008bd893105d2bc8bfb5e5dce1ef00fa09008533 (patch) | |
tree | bd1c06c7f95a89242791255305c761dd6d0a133a | |
parent | 43818163155d5ce49414a8e54f5746a85606ba03 (diff) |
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>
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/cbi.js | 7 |
1 files changed, 6 insertions, 1 deletions
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]); |