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
protected
def get_user
@email = "#{params[:email]}.#{params[:format]}"
@email = CGI.unescape(params[:email])
User.where(email: @email).first
end
end
......@@ -2,7 +2,7 @@ module Emails
module AdminNotification
def send_admin_notification(user_id, subject, body)
email = recipient(user_id)
@unsubscribe_url = unsubscribe_url(email: email)
@unsubscribe_url = unsubscribe_url(email: CGI.escape(email))
@body = body
mail to: email, subject: subject
end
......
......@@ -5,13 +5,13 @@ describe UnsubscribesController do
describe "show" do
it "responds with success" do
get :show, email: 'me@example', format: 'com'
get :show, email: CGI.escape('me@example.com')
assert_response :success
end
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
end
......@@ -19,14 +19,14 @@ describe UnsubscribesController do
describe "create" 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
end
# Don't tell if the email does not exists
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
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