diff --git a/kong/conf_loader.lua b/kong/conf_loader.lua index 103895b08e6..831d386f224 100644 --- a/kong/conf_loader.lua +++ b/kong/conf_loader.lua @@ -151,6 +151,10 @@ local function check_and_infer(conf) -- separated strings to tables (but not when the arr has -- only one element) value = setmetatable(pl_stringx.split(value, ","), nil) -- remove List mt + + for i = 1, #value do + value[i] = pl_stringx.strip(value[i]) + end end if value == "" then diff --git a/spec/01-unit/02-conf_loader_spec.lua b/spec/01-unit/02-conf_loader_spec.lua index bdb43f9c2ea..5cb923c118d 100644 --- a/spec/01-unit/02-conf_loader_spec.lua +++ b/spec/01-unit/02-conf_loader_spec.lua @@ -154,6 +154,10 @@ describe("Configuration loader", function() assert.is_nil(getmetatable(conf.cassandra_contact_points)) assert.is_nil(getmetatable(conf.cassandra_data_centers)) end) + it("trims array values", function() + local conf = assert(conf_loader("spec/fixtures/to-strip.conf")) + assert.same({"dc1:2", "dc2:3", "dc3:4"}, conf.cassandra_data_centers) + end) it("infer ngx_boolean", function() local conf = assert(conf_loader(nil, { lua_code_cache = true diff --git a/spec/fixtures/to-strip.conf b/spec/fixtures/to-strip.conf index 5853a7d1a6f..474b07603b9 100644 --- a/spec/fixtures/to-strip.conf +++ b/spec/fixtures/to-strip.conf @@ -6,9 +6,11 @@ pg_ssl = off # Toggles client-server TLS connections dns_resolver = 8.8.8.8 +cassandra_data_centers = dc1:2, dc2:3 , dc3:4 + custom_plugins = foobar,hello-world # Comma-separated list of additional plugins # this node should load. # Use this property to load custom plugins # that are not bundled with Kong. # Plugins will be loaded from the - # `kong.plugins.{name}.*` namespace. \ No newline at end of file + # `kong.plugins.{name}.*` namespace.