Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sanitizing body responses to deal with bad characters.
- Loading branch information
Fábio Neves
committed
Sep 11, 2015
1 parent
7062ccf
commit 3b09283
Showing
4 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'scrub_rb' | ||
|
||
module ZendeskAPI | ||
module Middleware | ||
module Response | ||
class SanitizeResponse < Faraday::Response::Middleware | ||
def on_complete(env) | ||
env[:body].scrub!('') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'core/spec_helper' | ||
|
||
describe ZendeskAPI::Middleware::Response::SanitizeResponse do | ||
def fake_response(data) | ||
stub_json_request(:get, %r{blergh}, data) | ||
response = client.connection.get('blergh') | ||
expect(response.status).to eq(200) | ||
response | ||
end | ||
|
||
describe 'with bad characters' do | ||
let(:response) { fake_response("{\"x\":\"2012-02-01T13:14:15Z\", \"y\":\"\u0315\u0316\u01333\u0270\u022712awesome!\ud83d\udc4d\"}") } | ||
|
||
it 'removes bad characters' do | ||
expect(response.body.to_s.valid_encoding?).to be(true) | ||
expect(response.body['y'].to_s).to eq("\u0315\u0316\u01333\u0270\u022712awesome!") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters