From: Paul Donald Date: Mon, 23 Dec 2024 17:14:40 +0000 (+0000) Subject: luci-base: amend path() to handle arrays better X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0826411de7c5a107138cf00d1171fde13a1637ec;p=project%2Fluci.git luci-base: amend path() to handle arrays better While the jsdoc for this function describes a string[] parameter, this seemingly was not handled; consistent usage of various L.(url|resource|etc) is multiple strings that become object properties. E.g.: L.resource('lldpd/lldpd.css'); L.url("admin", "system", "leds"); which become e.g.: Arguments { 0: "admin/network", 1: "routes", … } Handle a string[] parameter, by re-entering the function with any Array[] parameter. follow-up fix to 7c2cde52dbb14d5e878ca775946db9b3f13dcf1d This prevents: TypeError parts[i].startsWith is not a function Signed-off-by: Paul Donald --- diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 4107a9019b..1a5fecc8b3 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -2754,9 +2754,14 @@ path(prefix = '', parts) { const url = [ prefix ]; - for (let i = 0; i < parts.length; i++) - if (/^(?:[a-zA-Z0-9_.%,;-]+\/)*[a-zA-Z0-9_.%,;-]+$/.test(parts[i]) || /^\?[a-zA-Z0-9_.%=&;-]+$/.test(parts[i])) - url.push(parts[i].startsWith('?') ? parts[i] : '/' + parts[i]); + for (let i = 0; i < parts.length; i++){ + const part = parts[i]; + if (Array.isArray(part)) + url.push(this.path('', part)); + else + if (/^(?:[a-zA-Z0-9_.%,;-]+\/)*[a-zA-Z0-9_.%,;-]+$/.test(part) || /^\?[a-zA-Z0-9_.%=&;-]+$/.test(part)) + url.push(part.startsWith('?') ? part : '/' + part); + } if (url.length === 1) url.push('/');