Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config) allow octothorpes in config directives #2411

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ local function check_and_infer(conf)
local typ = v_schema.typ

if type(value) == "string" then
value = string.gsub(value, "#.-$", "") -- remove trailing comment if any

-- remove trailing comment, if any
-- and remove escape chars from octothorpes
value = string.gsub(value, "[^\\]#.-$", "")
value = string.gsub(value, "\\#", "#")

value = pl_stringx.strip(value)
end

Expand Down
4 changes: 4 additions & 0 deletions spec/01-unit/02-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ describe("Configuration loader", function()
assert.True(conf.plugins.foobar)
assert.True(conf.plugins["hello-world"])
end)
it("correctly parses values containing an octothorpe", function()
local conf = assert(conf_loader("spec/fixtures/to-strip.conf"))
assert.equal("test#123", conf.pg_password)
end)

describe("nginx_user", function()
it("is nil by default", function()
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/to-strip.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ log_level = debug # strip this
pg_ssl = off # Toggles client-server TLS connections
# between Kong and PostgreSQL.

pg_password = test\#123 # do not strip an escaped octothorpe

dns_resolver = 8.8.8.8

cassandra_data_centers = dc1:2, dc2:3 , dc3:4
Expand Down