Skip to content

Commit

Permalink
Force encode request body if it's a string
Browse files Browse the repository at this point in the history
This fixes #1475
  • Loading branch information
st0012 committed Jun 25, 2021
1 parent d82b463 commit 4aa09ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions sentry-ruby/lib/sentry/interfaces/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def read_data_from(request)
request.POST
elsif request.body # JSON requests, etc
data = request.body.read(MAX_BODY_LIMIT)
data = data.force_encoding(Encoding::UTF_8) if data.respond_to?(:force_encoding)
request.body.rewind
data
end
Expand Down
10 changes: 10 additions & 0 deletions sentry-ruby/spec/sentry/interfaces/request_interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ def to_s
expect(interface.data).to eq("catch me")
end

it "force encodes request body to avoid encoding issue" do
new_env = env.merge(::Rack::RACK_INPUT => StringIO.new("あ"))

interface = described_class.build(env: new_env)

expect do
JSON.generate(interface.to_hash)
end.not_to raise_error
end

it "doesn't remove ip address headers" do
ip = "1.1.1.1"

Expand Down

0 comments on commit 4aa09ba

Please sign in to comment.