From 132baf10e54c8fc2ae374ff15fbd75cccfdb2651 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sat, 14 Oct 2023 17:41:22 +0800 Subject: [PATCH] replace_dashes_lower --- kong/router/atc.lua | 4 ++-- kong/router/compat.lua | 6 +++--- kong/tools/string.lua | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kong/router/atc.lua b/kong/router/atc.lua index 095095fc94b2..7c59cba03b4d 100644 --- a/kong/router/atc.lua +++ b/kong/router/atc.lua @@ -562,7 +562,7 @@ local get_queries_key do local tb_sort = table.sort local tb_concat = table.concat - local replace_dashes = require("kong.tools.string").replace_dashes + local replace_dashes_lower = require("kong.tools.string").replace_dashes_lower local str_buf = buffer.new(64) @@ -571,7 +571,7 @@ do -- NOTE: DO NOT yield until str_buf:get() for name, value in pairs(headers) do - local name = replace_dashes(name):lower() + local name = replace_dashes_lower(name) if type(value) == "table" then for i, v in ipairs(value) do diff --git a/kong/router/compat.lua b/kong/router/compat.lua index d76c741d63ef..6da3522f4698 100644 --- a/kong/router/compat.lua +++ b/kong/router/compat.lua @@ -10,8 +10,8 @@ local tb_nkeys = require("table.nkeys") local uuid = require("resty.jit-uuid") -local shallow_copy = require("kong.tools.utils").shallow_copy -local replace_dashes = require("kong.tools.string").replace_dashes +local shallow_copy = require("kong.tools.utils").shallow_copy +local replace_dashes_lower = require("kong.tools.string").replace_dashes_lower local is_regex_magic = utils.is_regex_magic @@ -252,7 +252,7 @@ local function get_expression(route) single_header_buf:reset():put("(") for i, value in ipairs(v) do - local name = "any(http.headers." .. replace_dashes(h):lower() .. ")" + local name = "any(http.headers." .. replace_dashes_lower(h) .. ")" local op = OP_EQUAL -- value starts with "~*" diff --git a/kong/tools/string.lua b/kong/tools/string.lua index 3340de41b31a..3ed03a5d293a 100644 --- a/kong/tools/string.lua +++ b/kong/tools/string.lua @@ -6,6 +6,7 @@ local _M = {} local replace_dashes +local replace_dashes_lower do local str_replace_char @@ -31,8 +32,13 @@ do replace_dashes = function(str) return str_replace_char(str, "-", "_") end + + replace_dashes_lower = function(str) + return str_replace_char(str:lower(), "-", "_") + end end _M.replace_dashes = replace_dashes +_M.replace_dashes_lower = replace_dashes_lower return _M