luci-base: cbi.js: handle undefined arguments in formatting
authorJo-Philipp Wich <jo@mein.io>
Thu, 4 Aug 2016 09:45:04 +0000 (11:45 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 4 Aug 2016 09:45:30 +0000 (11:45 +0200)
Fix the JavaScript String.format() to not trigger an exception if the argument
for an escaped format like %h or %q is undefined.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index b285ee2..5790e30 100644 (file)
@@ -1300,6 +1300,9 @@ String.prototype.format = function()
        var quot_esc = [/"/g, '&#34;', /'/g, '&#39;'];
 
        function esc(s, r) {
+               if (typeof(s) !== 'string' && !(s instanceof String))
+                       return '';
+
                for( var i = 0; i < r.length; i += 2 )
                        s = s.replace(r[i], r[i+1]);
                return s;