Skip to content

Commit 10d9c4d

Browse files
committed
transplant #9451
1 parent 7911168 commit 10d9c4d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

kong/router/atc.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local lrucache = require("resty.lrucache")
99
local server_name = require("ngx.ssl").server_name
1010
local tb_new = require("table.new")
1111
local tb_clear = require("table.clear")
12+
local isempty = require("table.isempty")
1213
local utils = require("kong.router.utils")
1314
local yield = require("kong.tools.utils").yield
1415

@@ -80,8 +81,13 @@ local function escape_str(str)
8081
end
8182

8283

84+
local function is_empty_field(f)
85+
return f == nil or f == null or isempty(f)
86+
end
87+
88+
8389
local function gen_for_field(name, op, vals, val_transform)
84-
if not vals or vals == null then
90+
if is_empty_field(vals) then
8591
return nil
8692
end
8793

@@ -520,6 +526,7 @@ end
520526

521527

522528
_M.escape_str = escape_str
529+
_M.is_empty_field = is_empty_field
523530
_M.gen_for_field = gen_for_field
524531
_M.split_host_port = split_host_port
525532

kong/router/compat.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local tb_nkeys = require("table.nkeys")
99

1010

1111
local escape_str = atc.escape_str
12+
local is_empty_field = atc.is_empty_field
1213
local gen_for_field = atc.gen_for_field
1314
local split_host_port = atc.split_host_port
1415

@@ -76,7 +77,7 @@ local function get_expression(route)
7677
tb_insert(out, gen)
7778
end
7879

79-
if hosts and hosts ~= null then
80+
if not is_empty_field(hosts) then
8081
tb_clear(exp_hosts_t)
8182
local hosts_t = exp_hosts_t
8283

@@ -133,7 +134,7 @@ local function get_expression(route)
133134
tb_insert(out, gen)
134135
end
135136

136-
if headers and headers ~= null then
137+
if not is_empty_field(headers) then
137138
tb_clear(exp_headers_t)
138139
local headers_t = exp_headers_t
139140

0 commit comments

Comments
 (0)