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

Bugfix: failure of generating error-logs when a HTTP response body includes multibyte-chars #208

Merged
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
7 changes: 7 additions & 0 deletions lib/rsolr/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,16 @@ class Http < RuntimeError
}

def initialize request, response
response = response_with_force_encoded_body(response)
@request, @response = request, response
end

private

def response_with_force_encoded_body(response)
response[:body] = response[:body].force_encoding('UTF-8')
response
end
end

# Thrown if the :wt is :ruby
Expand Down
8 changes: 8 additions & 0 deletions spec/api/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,13 @@ def generate_error_with_backtrace(request, response)
let(:response_body) { (response_lines << "'error'=>{'msg'=> #{msg}").join("\n") }
it { should include msg }
end

context "when the response body is made of multi-byte chars and encoded by ASCII-8bit" do
let (:response_lines) { (1..15).to_a.map { |i| "レスポンス #{i}".b } }

it "encodes errorlogs by UTF-8" do
expect(subject.encoding.to_s).to eq 'UTF-8'
end
end
end
end