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

Encode query parameters. #9

Merged
merged 1 commit into from
Aug 16, 2017
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
9 changes: 1 addition & 8 deletions lib/smartystreets_ruby_sdk/native_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ def build_http(request)
end

def self.create_query(smarty_request)
query_string = ''

smarty_request.parameters.each do |key, value|
query_string.concat("&#{key}=#{value}")
end

query_string[0] = ''
query_string
URI.encode_www_form(smarty_request.parameters)
end

def self.set_custom_headers(smarty_headers, request)
Expand Down
16 changes: 15 additions & 1 deletion test/smartystreets_ruby_sdk/test_native_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ def test_query_contains_correct_parameters
assert_equal('auth-id=testID&auth-token=testToken', query)
end

def test_query_encodes_parameters
smarty_request = Request.new
smarty_request.url_prefix = 'http://localhost'
smarty_request.payload = 'Test Payload'
smarty_request.parameters = {
'needs_encoding' => '&foo=bar',
'unicode' => 'Sjömadsvägen'
}

query = NativeSender.create_query(smarty_request)

assert_equal('needs_encoding=%26foo%3Dbar&unicode=Sj%C3%B6madsv%C3%A4gen', query)
end

def test_request_contains_correct_content
smarty_request = Request.new
smarty_request.url_prefix = 'http://localhost'
Expand Down Expand Up @@ -120,4 +134,4 @@ def test_request_has_all_added_custom_headers
assert_equal("smartystreets (sdk:ruby@#{SmartyStreets::VERSION}), Some plugin, Some other plugin", native_request['User-Agent'])
assert_equal('X value', native_request['X-Something'])
end
end
end