Skip to content

Commit 08823ae

Browse files
authored
Merge pull request #92 from 1SecondEveryday/fix/filter-param-symbol-keys
Handle symbol param keys during filtering
2 parents a17c5f5 + 586dc23 commit 08823ae

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Changelog
22

3-
## [2.1.1] - Unreleased
3+
## [2.1.1] - 2025-07-09
44

5-
## Added or Changed or Fixed
6-
- Your contribution here.
5+
### Fixed
6+
- [#92](https://github.com/aserafin/grape_logging/pull/92) Handle symbol param keys during filtering - [@samsonjs](https://github.com/samsonjs).
77

8-
[2.1.1]: https://github.com/aserafin/grape_logging/compare/v2.1.0...master
8+
[2.1.1]: https://github.com/aserafin/grape_logging/compare/v2.1.0...v2.1.1
99

1010
## [2.1.0] - 2025-07-09
1111

12-
## Added
12+
### Added
1313
- [#91](https://github.com/aserafin/grape_logging/pull/91) Add ActionDispatch request ID to logger arguments hash as `:request_id` - [@samsonjs](https://github.com/samsonjs).
1414

1515
[2.1.0]: https://github.com/aserafin/grape_logging/compare/v2.0.0...v2.1.0

RELEASING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Check that the last build succeeded in [GitHub Actions](https://github.com/asera
1515

1616
### Update Changelog
1717

18-
Change "Next Release" in [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md) to the new version and date:
18+
Change "Unreleased" in [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md) to the new version and date:
1919

2020
```
2121
## [1.8.5] - 2024-06-28
@@ -96,10 +96,12 @@ end
9696
Add the next release to [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md).
9797

9898
```
99-
## [Next Release]
99+
## [1.8.6] - Unreleased
100100
101101
### Changed or Fixed or Added
102102
- Your contribution here.
103+
104+
[1.8.6]: https://github.com/aserafin/grape_logging/compare/v1.8.5...master
103105
```
104106

105107
Commit your changes.

lib/grape_logging/loggers/filter_parameters.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ def clean_parameters(parameters)
3737

3838
def build_encoding_map(parameters)
3939
parameters.each_with_object({}) do |(k, v), h|
40-
h[k.dup.force_encoding(Encoding::ASCII_8BIT)] = [k.encoding, v.is_a?(Hash) ? build_encoding_map(v) : nil]
40+
key_str = k.to_s
41+
h[key_str.dup.force_encoding(Encoding::ASCII_8BIT)] = [key_str.encoding, v.is_a?(Hash) ? build_encoding_map(v) : nil]
4142
end
4243
end
4344

4445
def transform_key_encoding(parameters, encoding_map)
4546
parameters.each_with_object({}) do |(k, v), h|
46-
encoding, children_encoding_map = encoding_map[k]
47-
h[k.dup.force_encoding(encoding)] = v.is_a?(Hash) ? transform_key_encoding(v, children_encoding_map) : v
47+
key_str = k.to_s
48+
encoding, children_encoding_map = encoding_map[key_str]
49+
h[key_str.dup.force_encoding(encoding)] = v.is_a?(Hash) ? transform_key_encoding(v, children_encoding_map) : v
4850
end
4951
end
5052
end

spec/lib/grape_logging/loggers/filter_parameters_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,14 @@
7878
let(:replacement) { 'CUSTOM_REPLACEMENT' }
7979
it_behaves_like 'filtering'
8080
end
81+
82+
context 'with symbol keys, which occur during automated testing' do
83+
let(:mock_request) { OpenStruct.new(params: { sneaky_symbol: 'hey!' }) }
84+
85+
it 'converts keys to strings' do
86+
expect(subject.parameters(mock_request, nil)).to eq(params: {
87+
'sneaky_symbol' => 'hey!',
88+
})
89+
end
90+
end
8191
end

0 commit comments

Comments
 (0)