Skip to content

Commit

Permalink
Handle invalid placeholder attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
  • Loading branch information
okkez committed Jan 31, 2019
1 parent aeba796 commit 7f455f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fluent/plugin/filter_geoip.rb
Expand Up @@ -86,6 +86,7 @@ def configure(conf)
@placeholder_keys = @map.values.join.scan(REGEXP_PLACEHOLDER_SCAN).map{|placeholder| placeholder[0] }.uniq
@placeholder_keys.each do |key|
m = key.match(REGEXP_PLACEHOLDER_SINGLE)
raise Fluent::ConfigError, "Invalid placeholder attributes: #{key}" unless m
geoip_key = m[:geoip_key]
case @backend_library
when :geoip
Expand Down
13 changes: 13 additions & 0 deletions test/plugin/test_filter_geoip.rb
Expand Up @@ -115,6 +115,19 @@ def db.lookup(ip)
]
end

test "invalid placeholder attributes" do
assert_raise(Fluent::ConfigParseError) do
create_driver %[
geoip_lookup_keys host
backend_library geoip2_c
<record>
geoip.city_name ${city.names.en["host]}
</record>
]
end
end

data(geoip: "geoip",
geoip2_compat: "geoip2_compat")
test "unsupported key" do |backend|
Expand Down

0 comments on commit 7f455f8

Please sign in to comment.