Use CGI encoding to ensure email address is transported correctly

Tnx to @jacobvosmaer for the suggestion
source: http://stackoverflow.com/questions/4394381/rails-url-helper-not-encoding-ampersands
parent 58933429
...@@ -16,7 +16,7 @@ class UnsubscribesController < ApplicationController ...@@ -16,7 +16,7 @@ class UnsubscribesController < ApplicationController
protected protected
def get_user def get_user
@email = "#{params[:email]}.#{params[:format]}" @email = CGI.unescape(params[:email])
User.where(email: @email).first User.where(email: @email).first
end end
end end
...@@ -2,7 +2,7 @@ module Emails ...@@ -2,7 +2,7 @@ module Emails
module AdminNotification module AdminNotification
def send_admin_notification(user_id, subject, body) def send_admin_notification(user_id, subject, body)
email = recipient(user_id) email = recipient(user_id)
@unsubscribe_url = unsubscribe_url(email: email) @unsubscribe_url = unsubscribe_url(email: CGI.escape(email))
@body = body @body = body
mail to: email, subject: subject mail to: email, subject: subject
end end
......
...@@ -5,13 +5,13 @@ describe UnsubscribesController do ...@@ -5,13 +5,13 @@ describe UnsubscribesController do
describe "show" do describe "show" do
it "responds with success" do it "responds with success" do
get :show, email: 'me@example', format: 'com' get :show, email: CGI.escape('me@example.com')
assert_response :success assert_response :success
end end
it "behaves the same if email address isn't known in the system" do it "behaves the same if email address isn't known in the system" do
get :show, email: 'i@dont_exists', format: 'com' get :show, email: CGI.escape('i@dont_exists.com')
assert_response :success assert_response :success
end end
...@@ -19,14 +19,14 @@ describe UnsubscribesController do ...@@ -19,14 +19,14 @@ describe UnsubscribesController do
describe "create" do describe "create" do
it "unsubscribes the connected user" do it "unsubscribes the connected user" do
post :create, email: 'me@example', format: 'com' post :create, email: CGI.escape('me@example.com')
assert user.reload.admin_email_unsubscribed_at assert user.reload.admin_email_unsubscribed_at
end end
# Don't tell if the email does not exists # Don't tell if the email does not exists
it "behaves the same if email address isn't known in the system" do it "behaves the same if email address isn't known in the system" do
post :create, email: 'i@dont_exists', format: 'com' post :create, email: CGI.escape('i@dont_exists.com')
assert_response :redirect assert_response :redirect
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment