luci-base: modify path function to allow URI parameters
authorPaul Donald <newtwen+github@gmail.com>
Thu, 19 Dec 2024 17:43:10 +0000 (17:43 +0000)
committerPaul Donald <newtwen+github@gmail.com>
Thu, 19 Dec 2024 17:43:10 +0000 (17:43 +0000)
Allows usage such as:
 L.url("admin", "system", "package-manager", "?query=package")

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
modules/luci-base/htdocs/luci-static/resources/luci.js

index 24e17b9ad6b78018b0249194dd87a8d8cabce144..aae9a2abceb28f9e895ab2b43f7fc082b50c1f87 100644 (file)
                 * Construct a relative URL path from the given prefix and parts.
                 * The resulting URL is guaranteed to only contain the characters
                 * `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well
-                * as `/` for the path separator.
+                * as `/` for the path separator. Suffixing '?x=y&foo=bar' URI
+                * parameters also limited to the aforementioned characters is
+                * permissible.
                 *
                 * @instance
                 * @memberof LuCI
                        var url = [ prefix || '' ];
 
                        for (var i = 0; i < parts.length; i++)
-                               if (/^(?:[a-zA-Z0-9_.%,;-]+\/)*[a-zA-Z0-9_.%,;-]+$/.test(parts[i]))
-                                       url.push('/', parts[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]);
 
                        if (url.length === 1)
                                url.push('/');
                 *
                 * The resulting URL is guaranteed to only contain the characters
                 * `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well
-                * as `/` for the path separator.
+                * as `/` for the path separator. Suffixing '?x=y&foo=bar' URI
+                * parameters also limited to the aforementioned characters is
+                * permissible.
                 *
                 * @instance
                 * @memberof LuCI
                 *
                 * The resulting URL is guaranteed to only contain the characters
                 * `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well
-                * as `/` for the path separator.
+                * as `/` for the path separator. Suffixing '?x=y&foo=bar' URI
+                * parameters also limited to the aforementioned characters is
+                * permissible.
                 *
                 * @instance
                 * @memberof LuCI
                 *
                 * The resulting URL is guaranteed to only contain the characters
                 * `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well
-                * as `/` for the path separator.
+                * as `/` for the path separator. Suffixing '?x=y&foo=bar' URI
+                * parameters also limited to the aforementioned characters is
+                * permissible.
                 *
                 * @instance
                 * @memberof LuCI