Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Can't modify frozen string" error when converting boolean to string #171

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.5.8
- Fix "Can't modify frozen string" error when converting boolean to `string` [#171](https://github.com/logstash-plugins/logstash-filter-mutate/pull/171)

## 3.5.7
- Clarify that `split` and `join` also support strings [#164](https://github.com/logstash-plugins/logstash-filter-mutate/pull/164)

Expand Down
2 changes: 1 addition & 1 deletion lib/logstash/filters/mutate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def convert_string(value)
# target encoding and only change if necessary, so calling
# valid_encoding? is redundant
# see https://twitter.com/jordansissel/status/444613207143903232
value.to_s.force_encoding(Encoding::UTF_8)
(+value.to_s).force_encoding(Encoding::UTF_8)
edmocosta marked this conversation as resolved.
Show resolved Hide resolved
end

def convert_boolean(value)
Expand Down
2 changes: 1 addition & 1 deletion logstash-filter-mutate.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-filter-mutate'
s.version = '3.5.7'
s.version = '3.5.8'
s.licenses = ['Apache License (2.0)']
s.summary = "Performs mutations on fields"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down
20 changes: 20 additions & 0 deletions spec/filters/mutate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,26 @@ def pattern_path(path)
end
end

describe "convert auto-frozen values to string" do
config <<-CONFIG
filter {
mutate {
convert => {
"true_field" => "string"
"false_field" => "string"
}
}
}
CONFIG

sample({ "true_field" => true, "false_field" => false }) do
expect(subject.get("true_field")).to eq "true"
expect(subject.get("true_field")).to be_a(String)
expect(subject.get("false_field")).to eq "false"
expect(subject.get("false_field")).to be_a(String)
end
end

#LOGSTASH-1529
describe "gsub on a String with dynamic fields (%{}) in pattern" do
config '
Expand Down