Skip to content
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
10 changes: 8 additions & 2 deletions lib/fluent/plugin_helper/record_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def self.parse_dot_array_op(key, param)
if i = key.index(']')
index_value = key[0..i - 1]
raise Fluent::ConfigError, "missing array index in '[]'. Invalid syntax: #{param}" if index_value == ']'
result << Integer(index_value)
result << parse_array_index(index_value, param)
key = key[i + 1..-1]
in_bracket = false
else
Expand All @@ -159,6 +159,12 @@ def self.parse_dot_array_op(key, param)
result
end

def self.parse_array_index(index_value, param)
Integer(index_value)
rescue ArgumentError
raise Fluent::ConfigError, "array index must be an integer: '#{index_value}'. Invalid syntax: #{param}"
end

def self.parse_bracket_notation(param)
orig_param = param
result = []
Expand All @@ -180,7 +186,7 @@ def self.parse_bracket_notation(param)
if i = param.index(']')
index_value = param[0..i - 1]
raise Fluent::ConfigError, "missing array index in '[]'. Invalid syntax: #{param}" if index_value == ']'
result << Integer(index_value)
result << parse_array_index(index_value, orig_param)
param = param[i + 1..-1]
in_bracket = false
else
Expand Down
4 changes: 4 additions & 0 deletions test/plugin_helper/test_record_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Dummy < Fluent::Plugin::TestBase
data("missing ']'" => "$['key1'",
"missing array index with dot" => "$.hello[]",
"missing array index with bracket" => "$[]",
"non-integer array index with dot" => "$.key1[x]",
"non-integer array index with bracket" => "$['key1'][x]",
"more chars" => "$.key1[0]foo",
"whitespace char included key in dot notation" => "$.key[0].ke y",
"empty keys with dot" => "$.",
Expand Down Expand Up @@ -142,6 +144,8 @@ class Dummy < Fluent::Plugin::TestBase
data("missing ']'" => "$['key1'",
"missing array index with dot" => "$.hello[]",
"missing array index with bracket" => "$['hello'][]",
"non-integer array index with dot" => "$.key1[x]",
"non-integer array index with bracket" => "$['key1'][x]",
"whitespace char included key in dot notation" => "$.key[0].ke y",
"more chars" => "$.key1[0]foo",
"empty keys with dot" => "$.",
Expand Down
Loading