From 1369ee74a6af64298a09b32f580d6c4fdd9a05c5 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Wed, 23 Apr 2025 14:04:12 +0200 Subject: [PATCH] luci-base: prevent tools.widgets.ZoneSelect tracebacks follow-up fix for 0be4ad51a0bea3e1e3e6cd7d646e11ec6c722540 It seems to have been this way for a while, for zone selections involving the 'any' ('*') choice. firewall forwards.js has no 'this.allowany;' property on the widgets, so the any choice is absent, leading to a traceback, caused by the 'src' widget, even though this code block operates on the 'dst' value. Certain combinations of 'src' and 'dst' also triggered tracebacks. This might not be the correct behaviour for this widget, but it does prevent tracebacks caused by null values. Signed-off-by: Paul Donald (cherry picked from commit aa6924cd4ce64cc6e4ced50b0603f9f34b3e619c) --- .../luci-static/resources/tools/widgets.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js index 8bd6456572..0e72d51034 100644 --- a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js +++ b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js @@ -186,26 +186,27 @@ var CBIZoneSelect = form.ListValue.extend({ emptyval.parentNode.removeChild(emptyval); } else { - var anyval = node.querySelector('[data-value="*"]'), - emptyval = node.querySelector('[data-value=""]'); + const anyval = node.querySelector('[data-value="*"]') || ''; + const emptyval = node.querySelector('[data-value=""]') || ''; - if (emptyval == null) { + if (emptyval == null && anyval) { emptyval = anyval.cloneNode(true); emptyval.removeAttribute('display'); emptyval.removeAttribute('selected'); emptyval.setAttribute('data-value', ''); } - if (opt[0].allowlocal) + if (opt[0]?.allowlocal && emptyval) L.dom.content(emptyval.querySelector('span'), [ E('strong', _('Device')), E('span', ' (%s)'.format(_('input'))) ]); + if (opt[0]?.allowany && anyval && emptyval) { + L.dom.content(anyval.querySelector('span'), [ + E('strong', _('Any zone')), E('span', ' (%s)'.format(_('forward'))) + ]); - L.dom.content(anyval.querySelector('span'), [ - E('strong', _('Any zone')), E('span', ' (%s)'.format(_('forward'))) - ]); - - anyval.parentNode.insertBefore(emptyval, anyval); + anyval.parentNode.insertBefore(emptyval, anyval); + } } }, this)); -- 2.30.2