diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 0085d8b63ec7..1a0b41bbd3ca 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -156,8 +156,8 @@ local function extract_options(db, args, schema, context) end if schema.fields.tags and args.tags ~= nil and context == "page" then - if args.tags == null then - local error_message = "tags cannot be null (or empty string)" + if args.tags == null or #args.tags == 0 then + local error_message = "cannot be null" return nil, error_message, db[schema.name].errors:invalid_options({tags = error_message}) end diff --git a/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua b/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua index cd40040fb653..fc7c87b48e05 100644 --- a/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua +++ b/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua @@ -290,7 +290,7 @@ describe("Admin API (#" .. strategy .. "): ", function() }) res = assert.res_status(400, res) local json = cjson.decode(res) - assert.same("invalid option (tags: tags cannot be null (or empty string))", json.message) + assert.same("invalid option (tags: cannot be null)", json.message) end) end) it("returns 405 on invalid method", function() diff --git a/spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua b/spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua index 9ea586fcdbab..8012e5d4d849 100644 --- a/spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua +++ b/spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua @@ -645,7 +645,7 @@ describe("Admin API: #" .. strategy, function() }) res = assert.res_status(400, res) local json = cjson.decode(res) - assert.same("invalid option (tags: tags cannot be null (or empty string))", json.message) + assert.same("invalid option (tags: cannot be null)", json.message) end) describe("empty results", function() diff --git a/spec/02-integration/04-admin_api/14-tags_spec.lua b/spec/02-integration/04-admin_api/14-tags_spec.lua index eab1db7536d0..99bb91d9adca 100644 --- a/spec/02-integration/04-admin_api/14-tags_spec.lua +++ b/spec/02-integration/04-admin_api/14-tags_spec.lua @@ -80,7 +80,17 @@ describe("Admin API - tags", function() }) local body = assert.res_status(400, res) local json = cjson.decode(body) - assert.same("invalid option (tags: tags cannot be null (or empty string))", json.message) + assert.same("invalid option (tags: cannot be null)", json.message) + end) + + it("filter by empty string tag", function() + local res = assert(client:send { + method = "GET", + path = "/consumers?tags=''" + }) + local body = assert.res_status(200, res) + local json = cjson.decode(body) + assert.equals(0, #json.data) end) it("filter by multiple tags with AND", function()