luci-mod-network: handle missing dnsrr hexdata as empty string
authorDaniel Nilsson <dannil+github@protonmail.com>
Mon, 6 Jan 2025 16:37:45 +0000 (17:37 +0100)
committerPaul Donald <newtwen+github@gmail.com>
Mon, 6 Jan 2025 17:22:15 +0000 (17:22 +0000)
If the value returned from UCI was falsy, it became an empty array instead
of an empty string, which crashed the UI when trying to invoke the
non-existing replace instance function on the value.

Signed-off-by: Daniel Nilsson <dannil+github@protonmail.com>
modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js

index 28d824a08e04b208ef9485d38acbfb601c75295f..afe21259ccb0cb18d2b5317c7121ee49bc3589f1 100644 (file)
@@ -1067,13 +1067,13 @@ return view.extend({
                ss.nodescriptions = true;
 
                function hexdecodeload(section_id) {
-                       let arr = uci.get('dhcp', section_id, this.option) || [];
+                       let value = uci.get('dhcp', section_id, this.option) || '';
                        // Remove any spaces or colons from the hex string - they're allowed
-                       arr = arr.replace(/[\s:]/g, '');
+                       value = value.replace(/[\s:]/g, '');
                        // Hex-decode the string before displaying
                        let decodedString = '';
-                       for (let i = 0; i < arr.length; i += 2) {
-                               decodedString += String.fromCharCode(parseInt(arr.substr(i, 2), 16));
+                       for (let i = 0; i < value.length; i += 2) {
+                               decodedString += String.fromCharCode(parseInt(value.substr(i, 2), 16));
                        }
                        return decodedString;
                }
@@ -1109,7 +1109,7 @@ return view.extend({
                so.width = '10%';
                so.rawhtml = true;
                so.load = function(section_id) {
-                       let hexdata = uci.get('dhcp', section_id, 'hexdata') || [];
+                       let hexdata = uci.get('dhcp', section_id, 'hexdata') || '';
                        hexdata = hexdata.replace(/[:]/g, '');
                        if (hexdata) {
                                return hexdata.replace(/(.{20})/g, '$1<br/>'); // Inserts <br> after every 2 characters (hex pair)