Skip to content

Commit

Permalink
feat(config) allow octothorpes in config directives
Browse files Browse the repository at this point in the history
Previously we treated all tokens after a comment character ("#")
as comments. This commit updates this behavior to recognize escaped
octothorpes as literal characters, and adjusted the directive
appropriately.
  • Loading branch information
p0pr0ck5 committed Apr 19, 2017
1 parent 9e83f10 commit ef883b1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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

0 comments on commit ef883b1

Please sign in to comment.