瀏覽代碼

[Fix] Fix regexp selector and add flattening

tags/2.6
Vsevolod Stakhov 4 年之前
父節點
當前提交
d43b852a02
共有 2 個文件被更改,包括 17 次插入5 次删除
  1. 13
    5
      lualib/lua_selectors/transforms.lua
  2. 4
    0
      test/lua/unit/selectors.lua

+ 13
- 5
lualib/lua_selectors/transforms.lua 查看文件

@@ -202,16 +202,24 @@ the second argument is optional hash type (`blake2`, `sha256`, `sha1`, `sha512`,
local res = re:search(inp, false, true)

if res then
if #res == 1 then
return res[1],'string'
-- Map all results in a single list
local flattened_table = {}
local function flatten_table(tbl)
for _, v in ipairs(tbl) do
if type(v) == 'table' then
flatten_table(v)
else
table.insert(flattened_table, v)
end
end
end

return res,'string_list'
flatten_table(res)
return flattened_table,'string_list'
end

return nil
end,
['description'] = 'Regexp matching',
['description'] = 'Regexp matching, returns all matches flattened in a single list',
['args_schema'] = {ts.string}
},
-- Returns a value if it exists in some map (or acts like a `filter` function)

+ 4
- 0
test/lua/unit/selectors.lua 查看文件

@@ -350,6 +350,10 @@ context("Selectors test", function()
selector = "header('Subject'):gsub('a', 'b')",
expect = {"Second, lower-cbsed hebder subject"}
},
["header regexp first"] = {
selector = "header('Subject').regexp('.*').first",
expect = {"Second, lower-cased header subject"}
},
}

for case_name, case in pairs(cases) do

Loading…
取消
儲存