diff options
| author | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-05 14:20:25 +0200 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-05 14:20:25 +0200 |
| commit | fc7967cb40ebffae26e4174608086c9a97dd88dd (patch) | |
| tree | 650c23882df035fe6e2a8d4a1cbad3939f0537bb | |
| parent | ba3f14d64d1af2289f4c55d016a6f57661be37a3 (diff) | |
Restrict boundary data
| -rw-r--r-- | yazi-enter.yazi/main.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/yazi-enter.yazi/main.lua b/yazi-enter.yazi/main.lua index 900f3d5..f9bddc5 100644 --- a/yazi-enter.yazi/main.lua +++ b/yazi-enter.yazi/main.lua @@ -123,7 +123,47 @@ local commit = ya.sync(function(_, mode, submitted_query) return 0 end) +local function require_plain_data(label, value, active_tables) + local value_type = type(value) + if value_type == "string" or value_type == "boolean" or value_type == "number" then + return + end + if value_type ~= "table" or getmetatable(value) ~= nil then + error(("yazi-enter: %s must use plain boundary data"):format(label), 0) + end + + active_tables = active_tables or {} + if active_tables[value] then + error(("yazi-enter: %s must not contain a table cycle"):format(label), 0) + end + active_tables[value] = true + + for key, item in pairs(value) do + local key_type = type(key) + if key_type ~= "string" and key_type ~= "number" then + error(("yazi-enter: %s must use string or number table keys"):format(label), 0) + end + require_plain_data(label, item, active_tables) + end + + active_tables[value] = nil +end + +local function require_string(label, value) + if type(value) ~= "string" then + error(("yazi-enter: %s must be a string"):format(label), 0) + end +end + local function new_search_policy(intent) + if + type(intent.previous) ~= "boolean" + or type(intent.smart) ~= "boolean" + or type(intent.insensitive) ~= "boolean" + then + error("yazi-enter: search policy values must be Booleans", 0) + end + return { previous = intent.previous, smart = intent.smart, @@ -139,9 +179,19 @@ local function new_application_boundaries( ) return { prompt = function(prompt_data) + if type(prompt_data) ~= "table" then + error("yazi-enter: prompt data must be a table", 0) + end + require_plain_data("prompt data", prompt_data) return prompt_capability(prompt_data) end, find_update = function(query, search_policy) + require_string("Find query", query) + if type(search_policy) ~= "table" then + error("yazi-enter: search policy must be a table", 0) + end + require_plain_data("search policy", search_policy) + local result, error_status = find_update_capability(query, search_policy) if result ~= UPDATE_SUCCESS and result ~= UPDATE_FAILURE then error("yazi-enter: Find update capability returned an invalid result", 0) @@ -149,6 +199,9 @@ local function new_application_boundaries( return result, error_status end, commit = function(mode, submitted_query) + require_string("commit mode", mode) + require_string("submitted query", submitted_query) + local dispatch_count = commit_capability(mode, submitted_query) if dispatch_count ~= 0 and dispatch_count ~= 1 then error("yazi-enter: commit capability returned an invalid dispatch count", 0) |