luci-base, luci-lua-runtime: fix "dispatched" and "requested" properties
authorJo-Philipp Wich <[email protected]>
Mon, 21 Nov 2022 11:24:31 +0000 (12:24 +0100)
committerJo-Philipp Wich <[email protected]>
Mon, 21 Nov 2022 11:24:31 +0000 (12:24 +0100)
Ensure to properly emulate the "dispatched" and "requested" properties
which refer to the executed and initially resolved menu node respectivey.

Also stop exposing a `node` property in Lua context to maintain full
compatibility with the old Lua runtime.

Signed-off-by: Jo-Philipp Wich <[email protected]>
modules/luci-base/ucode/dispatcher.uc
modules/luci-lua-runtime/luasrc/dispatcher.lua

index b08a2f8b7ae8f6d6d840d410ce96205988664957..c996c76af1075ce8475a31766ac29a32bf6c5e60 100644 (file)
@@ -856,7 +856,7 @@ dispatch = function(_http, path) {
        let version = determine_version();
        let lang = determine_request_language();
 
-       runtime = LuCIRuntime({
+       runtime = runtime || LuCIRuntime({
                http,
                ubus,
                uci,
@@ -892,7 +892,8 @@ dispatch = function(_http, path) {
                let resolved = resolve_page(menu, path);
 
                runtime.env.ctx = resolved.ctx;
-               runtime.env.node = resolved.node;
+               runtime.env.dispatched = resolved.node;
+               runtime.env.requested ??= resolved.node;
 
                if (length(resolved.ctx.auth)) {
                        let session = is_authenticated(resolved.ctx.auth);
index f97e84a69b820aa4479990e5ce9ea89c45bd6086..608b9b667439171f2c4b7add19f559ff5a47c6a3 100644 (file)
@@ -12,8 +12,6 @@ context = setmetatable({}, {
                        return _G.L.ctx.request_path
                elseif k == "requestargs" then
                        return _G.L.ctx.request_args
-               elseif k == "requested" or k == "dispatched" then
-                       return _G.L.node
                else
                        return _G.L.ctx[k]
                end