chore: format the string.find (#2785)

This commit is contained in:
Yousa 2020-11-18 23:58:36 +08:00 committed by GitHub
parent e7223e77a3
commit 208ae3d2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 16 deletions

View File

@ -36,6 +36,7 @@ setmetatable(_M, {__index = string})
-- find a needle from a haystack in the plain text way -- find a needle from a haystack in the plain text way
-- note: Make sure that the haystack is 'string' type, otherwise an exception will be thrown.
function _M.find(haystack, needle, from) function _M.find(haystack, needle, from)
return str_find(haystack, needle, from or 1, true) return str_find(haystack, needle, from or 1, true)
end end

View File

@ -28,7 +28,7 @@ local ngx = ngx
local ngx_timer_at = ngx.timer.at local ngx_timer_at = ngx.timer.at
local ngx_timer_every = ngx.timer.every local ngx_timer_every = ngx.timer.every
local string_sub = string.sub local string_sub = string.sub
local string_find = string.find local str_find = core.string.find
local log = core.log local log = core.log
local default_weight local default_weight
@ -76,9 +76,9 @@ local function service_info()
local basic_auth local basic_auth
-- TODO Add health check to get healthy nodes. -- TODO Add health check to get healthy nodes.
local url = host[math_random(#host)] local url = host[math_random(#host)]
local auth_idx = string_find(url, "@", 1, true) local auth_idx = str_find(url, "@")
if auth_idx then if auth_idx then
local protocol_idx = string_find(url, "://", 1, true) local protocol_idx = str_find(url, "://")
local protocol = string_sub(url, 1, protocol_idx + 2) local protocol = string_sub(url, 1, protocol_idx + 2)
local user_and_password = string_sub(url, protocol_idx + 3, auth_idx - 1) local user_and_password = string_sub(url, protocol_idx + 3, auth_idx - 1)
local other = string_sub(url, auth_idx + 1) local other = string_sub(url, auth_idx + 1)

View File

@ -20,7 +20,7 @@ local plugin = require("apisix.plugin")
local ngx = ngx local ngx = ngx
local ipairs = ipairs local ipairs = ipairs
local pairs = pairs local pairs = pairs
local str_find = string.find local str_find = core.string.find
local str_lower = string.lower local str_lower = string.lower
@ -163,7 +163,7 @@ local function set_common_header(data)
if outer_headers then if outer_headers then
for k, v in pairs(outer_headers) do for k, v in pairs(outer_headers) do
local is_content_header = str_find(k, "content-", 1, true) == 1 local is_content_header = str_find(k, "content-") == 1
-- skip header start with "content-" -- skip header start with "content-"
if not req.headers[k] and not is_content_header then if not req.headers[k] and not is_content_header then
req.headers[k] = v req.headers[k] = v

View File

@ -17,7 +17,7 @@
local core = require("apisix.core") local core = require("apisix.core")
local ngx = ngx local ngx = ngx
local plugin_name = "cors" local plugin_name = "cors"
local str_find = string.find local str_find = core.string.find
local re_gmatch = ngx.re.gmatch local re_gmatch = ngx.re.gmatch
@ -86,7 +86,7 @@ local _M = {
local function create_mutiple_origin_cache(conf) local function create_mutiple_origin_cache(conf)
if not str_find(conf.allow_origins, ",", 1, true) then if not str_find(conf.allow_origins, ",") then
return nil return nil
end end
local origin_cache = {} local origin_cache = {}

View File

@ -18,7 +18,7 @@ local ipairs = ipairs
local core = require("apisix.core") local core = require("apisix.core")
local ipmatcher = require("resty.ipmatcher") local ipmatcher = require("resty.ipmatcher")
local str_sub = string.sub local str_sub = string.sub
local str_find = string.find local str_find = core.string.find
local tonumber = tonumber local tonumber = tonumber
local lrucache = core.lrucache.new({ local lrucache = core.lrucache.new({
ttl = 300, count = 512 ttl = 300, count = 512
@ -69,7 +69,7 @@ local _M = {
local function valid_ip(ip) local function valid_ip(ip)
local mask = 0 local mask = 0
local sep_pos = str_find(ip, "/", 1, true) local sep_pos = str_find(ip, "/")
if sep_pos then if sep_pos then
mask = str_sub(ip, sep_pos + 1) mask = str_sub(ip, sep_pos + 1)
mask = tonumber(mask) mask = tonumber(mask)

View File

@ -25,6 +25,7 @@ local io = io
local os = os local os = os
local table = table local table = table
local string = string local string = string
local str_find = core.string.find
local local_conf local local_conf
@ -57,7 +58,7 @@ end
local function get_last_index(str, key) local function get_last_index(str, key)
local rev = string.reverse(str) local rev = string.reverse(str)
local _, idx = string.find(rev, key, 1, true) local _, idx = str_find(rev, key)
local n local n
if idx then if idx then
n = string.len(rev) - idx + 1 n = string.len(rev) - idx + 1

View File

@ -22,7 +22,7 @@ local ngx = ngx
local type = type local type = type
local re_sub = ngx.re.sub local re_sub = ngx.re.sub
local sub_str = string.sub local sub_str = string.sub
local find_str = string.find local str_find = core.string.find
local schema = { local schema = {
type = "object", type = "object",
@ -158,7 +158,7 @@ function _M.rewrite(conf, ctx)
end end
end end
local index = find_str(upstream_uri, "?", 1, true) local index = str_find(upstream_uri, "?")
if index then if index then
upstream_uri = core.utils.uri_safe_encode(sub_str(upstream_uri, 1, index-1)) .. upstream_uri = core.utils.uri_safe_encode(sub_str(upstream_uri, 1, index-1)) ..
sub_str(upstream_uri, index) sub_str(upstream_uri, index)

View File

@ -22,7 +22,7 @@ local config_util = require("apisix.core.config_util")
local ipairs = ipairs local ipairs = ipairs
local type = type local type = type
local error = error local error = error
local str_find = string.find local str_find = core.string.find
local aes = require "resty.aes" local aes = require "resty.aes"
local assert = assert local assert = assert
local str_gsub = string.gsub local str_gsub = string.gsub
@ -218,7 +218,7 @@ function _M.match_and_set(api_ctx)
if type(api_ctx.matched_sni) == "table" then if type(api_ctx.matched_sni) == "table" then
local matched = false local matched = false
for _, msni in ipairs(api_ctx.matched_sni) do for _, msni in ipairs(api_ctx.matched_sni) do
if sni_rev == msni or not str_find(sni_rev, ".", #msni, true) then if sni_rev == msni or not str_find(sni_rev, ".", #msni) then
matched = true matched = true
end end
end end
@ -233,7 +233,7 @@ function _M.match_and_set(api_ctx)
return false return false
end end
else else
if str_find(sni_rev, ".", #api_ctx.matched_sni, true) then if str_find(sni_rev, ".", #api_ctx.matched_sni) then
core.log.warn("failed to find any SSL certificate by SNI: ", core.log.warn("failed to find any SSL certificate by SNI: ",
sni, " matched SNI: ", api_ctx.matched_sni:reverse()) sni, " matched SNI: ", api_ctx.matched_sni:reverse())
return false return false

View File

@ -19,7 +19,7 @@ local json = require("cjson.safe")
local core = require("apisix.core") local core = require("apisix.core")
local aes = require "resty.aes" local aes = require "resty.aes"
local ngx_encode_base64 = ngx.encode_base64 local ngx_encode_base64 = ngx.encode_base64
local str_find = string.find local str_find = core.string.find
local dir_names = {} local dir_names = {}