From 161a2e9f61f13c84cc404177a5f5c12e1329666f Mon Sep 17 00:00:00 2001 From: Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> Date: Thu, 19 Aug 2021 18:09:14 +0100 Subject: [PATCH] fix(command parser): discard invalid lua expressions (#1124) --- lua/telescope/command.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/telescope/command.lua b/lua/telescope/command.lua index 01ed3c6..8d47f5a 100644 --- a/lua/telescope/command.lua +++ b/lua/telescope/command.lua @@ -97,10 +97,16 @@ local function convert_user_opts(user_opts) if ok then user_opts[key] = eval else - eval = assert(loadstring("return " .. val))() - if type(eval) == "table" then + local err + eval, err = loadstring("return " .. val) + if err ~= nil then + -- discard invalid lua expression + user_opts[key] = nil + elseif select("#", assert(eval)()) == 1 and type(assert(eval)()) == "table" then + -- allow if return a single table only user_opts[key] = eval else + -- otherwise return nil (allows split check later) user_opts[key] = nil end end