From 778e9a94e7b5aaf68f98d9f23d1c542ab4442408 Mon Sep 17 00:00:00 2001 From: soulbird Date: Thu, 24 Nov 2022 20:34:49 +0800 Subject: [PATCH] use has_prefix --- apisix/core/env.lua | 4 +++- apisix/core/utils.lua | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apisix/core/env.lua b/apisix/core/env.lua index 4d758ae6a9dd..09ef41d7da85 100644 --- a/apisix/core/env.lua +++ b/apisix/core/env.lua @@ -59,7 +59,9 @@ end local function is_env_ref(ref) - return type(ref) == "string" and sub(upper(ref), 1, 7) == ENV_PREFIX + -- Avoid the error caused by has_prefix to cause a crash, + -- so judge the type of ref. + return type(ref) == "string" and string.has_prefix(upper(ref), ENV_PREFIX) end diff --git a/apisix/core/utils.lua b/apisix/core/utils.lua index 2f6f6aab03e5..d74c48bc75e1 100644 --- a/apisix/core/utils.lua +++ b/apisix/core/utils.lua @@ -35,6 +35,7 @@ local base = require("resty.core.base") local open = io.open local sub_str = string.sub local str_byte = string.byte +local str_format = string.format local tonumber = tonumber local tostring = tostring local pairs = pairs @@ -352,7 +353,7 @@ do end local function retrieve(refs) - log.info(string.format("retrieve secrets refs: %p", refs)) + log.info(str_format("retrieve secrets refs: %p", refs)) local new_refs = table.deepcopy(refs) return retrieve_ref(new_refs)