Skip to content

Commit 5ba1d0d

Browse files
committed
Fix next url encoding error
Next URLs where not properly encoded and could pass the wrong information
1 parent 6485a39 commit 5ba1d0d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

mailauth/forms.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import urllib
2+
13
from django import forms
24
from django.contrib.auth import get_user_model
35
from django.contrib.sites.shortcuts import get_current_site
46
from django.core.mail import EmailMultiAlternatives
57
from django.db import connection
68
from django.template import TemplateDoesNotExist, loader
79
from django.urls import reverse
8-
from django.utils.encoding import iri_to_uri
910

1011
from mailauth.backends import MailAuthBackend
1112

@@ -34,7 +35,7 @@ def get_login_url(self, request, token, next=None):
3435
path=reverse("mailauth:login-token", kwargs={"token": token}),
3536
)
3637
if next is not None:
37-
url += "?next=%s" % iri_to_uri(next)
38+
url += "?next=%s" % urllib.parse.quote(next)
3839
return url
3940

4041
def get_token(self, user):

tests/test_forms.py

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ def test_save(self):
1111

1212

1313
class TestEmailLoginForm:
14+
def test_get_login_url(self, rf):
15+
request = rf.get("/")
16+
form = EmailLoginForm(request=request)
17+
assert (
18+
form.get_login_url(request, "TOKEN")
19+
== "http://testserver/accounts/login/TOKEN"
20+
)
21+
assert (
22+
form.get_login_url(
23+
request,
24+
"TOKEN",
25+
next="/path/?utm_source=website&utm_medium=email#some-anchor",
26+
)
27+
== "http://testserver/accounts/login/TOKEN?next=/path/%3Futm_source%3Dwebsite%26utm_medium%3Demail%23some-anchor"
28+
)
29+
1430
def test_send_mail__html_template(self):
1531
class MyEmailLoginForm(EmailLoginForm):
1632
html_email_template_name = EmailLoginForm.email_template_name

0 commit comments

Comments
 (0)