mirror of
https://github.com/samsonjs/grape_logging.git
synced 2026-03-25 08:55:47 +00:00
Handle symbol param keys during filtering
In testing these keys can be symbols, so when we're working with encodings make sure we have strings before trying to force any encodings on keys.
This commit is contained in:
parent
a17c5f52e4
commit
7e15b97cb4
2 changed files with 15 additions and 3 deletions
|
|
@ -37,14 +37,16 @@ module GrapeLogging
|
|||
|
||||
def build_encoding_map(parameters)
|
||||
parameters.each_with_object({}) do |(k, v), h|
|
||||
h[k.dup.force_encoding(Encoding::ASCII_8BIT)] = [k.encoding, v.is_a?(Hash) ? build_encoding_map(v) : nil]
|
||||
key_str = k.to_s
|
||||
h[key_str.dup.force_encoding(Encoding::ASCII_8BIT)] = [key_str.encoding, v.is_a?(Hash) ? build_encoding_map(v) : nil]
|
||||
end
|
||||
end
|
||||
|
||||
def transform_key_encoding(parameters, encoding_map)
|
||||
parameters.each_with_object({}) do |(k, v), h|
|
||||
encoding, children_encoding_map = encoding_map[k]
|
||||
h[k.dup.force_encoding(encoding)] = v.is_a?(Hash) ? transform_key_encoding(v, children_encoding_map) : v
|
||||
key_str = k.to_s
|
||||
encoding, children_encoding_map = encoding_map[key_str]
|
||||
h[key_str.dup.force_encoding(encoding)] = v.is_a?(Hash) ? transform_key_encoding(v, children_encoding_map) : v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -78,4 +78,14 @@ describe GrapeLogging::Loggers::FilterParameters do
|
|||
let(:replacement) { 'CUSTOM_REPLACEMENT' }
|
||||
it_behaves_like 'filtering'
|
||||
end
|
||||
|
||||
context 'with symbol keys, which occur during automated testing' do
|
||||
let(:mock_request) { OpenStruct.new(params: { sneaky_symbol: 'hey!' }) }
|
||||
|
||||
it 'converts keys to strings' do
|
||||
expect(subject.parameters(mock_request, nil)).to eq(params: {
|
||||
'sneaky_symbol' => 'hey!',
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue