Skip to content

Commit

Permalink
Manually encode ampersands (&) as required by the Keen API.
Browse files Browse the repository at this point in the history
* The system library URI::encode does not encode "&" since they are valid chars in a URL
  • Loading branch information
ccurtisj committed Aug 24, 2015
1 parent 903b6ca commit 92526ca
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/keen/client/publishing_methods.rb
Expand Up @@ -121,7 +121,7 @@ def beacon_url(event_collection, properties)
# @return a URL that will track an event when hit
def redirect_url(event_collection, properties, redirect_url)
require 'open-uri'
encoded_url = URI::encode(redirect_url)
encoded_url = CGI::escape(redirect_url)
json = MultiJson.encode(properties)
data = [json].pack("m0").tr("+/", "-_").gsub("\n", "")
"#{self.api_url}#{api_event_collection_resource_path(event_collection)}?api_key=#{self.write_key}&data=#{data}&redirect=#{encoded_url}"
Expand Down
2 changes: 1 addition & 1 deletion spec/keen/client/publishing_methods_spec.rb
Expand Up @@ -328,7 +328,7 @@
describe "redirect_url" do
it "should return a url with a base-64 encoded json param and an encoded redirect url" do
client.redirect_url("sign_ups", { :name => "Bob" }, "http://keen.io/?foo=bar&bar=baz").should ==
"#{api_url}/3.0/projects/12345/events/sign_ups?api_key=#{write_key}&data=eyJuYW1lIjoiQm9iIn0=&redirect=http://keen.io/?foo=bar&bar=baz"
"#{api_url}/3.0/projects/12345/events/sign_ups?api_key=#{write_key}&data=eyJuYW1lIjoiQm9iIn0=&redirect=http%3A%2F%2Fkeen.io%2F%3Ffoo%3Dbar%26bar%3Dbaz"
end
end

Expand Down

0 comments on commit 92526ca

Please sign in to comment.