From c653c94a02ea7cbca1a03cceb5beeb6f631b0fbe Mon Sep 17 00:00:00 2001 From: Hannu Nyman Date: Thu, 25 Jun 2026 23:14:58 +0300 Subject: [PATCH] treewide: escape slash chars in regex strings in .js files Properly escape the slash '/' chars that are included in the regex strings in javascript files. Slash is used as a regex delimiter in javascript, so an un-escaped slash may cause parsing errors in some tools like xgettext used with .po translation manipulation. Signed-off-by: Hannu Nyman --- modules/luci-base/htdocs/luci-static/resources/ui.js | 4 ++-- modules/luci-base/htdocs/luci-static/resources/validation.js | 2 +- .../htdocs/luci-static/resources/view/status/routes.js | 2 +- .../htdocs/luci-static/resources/protocol/openconnect.js | 2 +- .../htdocs/luci-static/resources/protocol/openfortivpn.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js index de466abe00..86a38a0cba 100644 --- a/modules/luci-base/htdocs/luci-static/resources/ui.js +++ b/modules/luci-base/htdocs/luci-static/resources/ui.js @@ -3362,7 +3362,7 @@ const UIFileUpload = UIElement.extend(/** @lends LuCI.ui.FileUpload.prototype */ * @returns {Promise} */ handleDelete(path, fileStat, ev) { - const parent = path.replace(/\/[^/]+$/, '') ?? '/'; + const parent = path.replace(/\/[^\/]+$/, '') ?? '/'; const name = path.replace(/^.+\//, ''); let msg; @@ -5102,7 +5102,7 @@ const UI = baseclass.extend(/** @lends LuCI.ui.prototype */ { for (let i = 0; i < 2; i++) for (let j = 0; j < ipaddrs.length; j++) tasks.push(this.pingDevice(i ? 'https' : 'http', ipaddrs[j]) - .then(ev => { reachable = ev.target.src.replace(/^(https?:\/\/[^/]+).*$/, '$1/') }, () => {})); + .then(ev => { reachable = ev.target.src.replace(/^(https?:\/\/[^\/]+).*$/, '$1/') }, () => {})); return Promise.all(tasks).then(() => { if (reachable) { diff --git a/modules/luci-base/htdocs/luci-static/resources/validation.js b/modules/luci-base/htdocs/luci-static/resources/validation.js index abd9e00948..1dfc66a46f 100644 --- a/modules/luci-base/htdocs/luci-static/resources/validation.js +++ b/modules/luci-base/htdocs/luci-static/resources/validation.js @@ -1003,7 +1003,7 @@ const ValidatorFactory = baseclass.extend(/** @lends LuCI.validation.ValidatorFa if (v == '.' || v == '..') return this.assert(false, _('valid network device name, not "." or ".."')); - return this.assert(v.match(/^[^:/%\s]{1,15}$/), _('valid network device name between 1 and 15 characters not containing ":", "/", "%" or spaces')); + return this.assert(v.match(/^[^:\/%\s]{1,15}$/), _('valid network device name between 1 and 15 characters not containing ":", "/", "%" or spaces')); }, /** diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/routes.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/routes.js index 5315d9e2b2..2f45df325d 100644 --- a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/routes.js +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/routes.js @@ -121,7 +121,7 @@ return view.extend({ const res = []; for (const line of routes.trim().split(/\n/)) { - const [, type = 'unicast', d, f = [] ] = (line.match(/^(?:([a-z_]+|\d+) )?(default|[0-9a-f:./]+) (.+)$/) || []); + const [, type = 'unicast', d, f = [] ] = (line.match(/^(?:([a-z_]+|\d+) )?(default|[0-9a-f:.\/]+) (.+)$/) || []); const dest = d == 'default' ? (v6 ? '::/0' : '0.0.0.0/0') : d; const flags = f?.trim?.().split?.(/\s+/); diff --git a/protocols/luci-proto-openconnect/htdocs/luci-static/resources/protocol/openconnect.js b/protocols/luci-proto-openconnect/htdocs/luci-static/resources/protocol/openconnect.js index 192eae52fd..2517767ea8 100644 --- a/protocols/luci-proto-openconnect/htdocs/luci-static/resources/protocol/openconnect.js +++ b/protocols/luci-proto-openconnect/htdocs/luci-static/resources/protocol/openconnect.js @@ -44,7 +44,7 @@ function validateCert(priv, section_id, value) { const beg = priv ? /^-----BEGIN (RSA )?PRIVATE KEY-----$/ : /^-----BEGIN CERTIFICATE-----$/; const end = priv ? /^-----END (RSA )?PRIVATE KEY-----$/ : /^-----END CERTIFICATE-----$/; const lines = value.trim().split(/[\r\n]/); - const base64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/; + const base64 = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/; const errmsg = _('This does not look like a valid PEM file'); diff --git a/protocols/luci-proto-openfortivpn/htdocs/luci-static/resources/protocol/openfortivpn.js b/protocols/luci-proto-openfortivpn/htdocs/luci-static/resources/protocol/openfortivpn.js index f1ec1ca91b..6a45697a98 100644 --- a/protocols/luci-proto-openfortivpn/htdocs/luci-static/resources/protocol/openfortivpn.js +++ b/protocols/luci-proto-openfortivpn/htdocs/luci-static/resources/protocol/openfortivpn.js @@ -48,7 +48,7 @@ function validateCert(priv, section_id, value) { for (i = 0; i < lines.length; i++) { if (lines[i].match(/^-{5}BEGIN ((|RSA |DSA )PRIVATE KEY|(|TRUSTED |X509 )CERTIFICATE)-{5}$/)) start = true; - else if (start && !lines[i].match(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/)) + else if (start && !lines[i].match(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)) break; }