diff --git a/README.md b/README.md index 81a4727..2448924 100644 --- a/README.md +++ b/README.md @@ -407,6 +407,10 @@ You may need to do this if you use a custom user model and upgrade Django. ## Change Log +### 4.3.0 (2023-06-07) + +* added tolerance to the ending slash in URL + ### 4.2.0 (2023-01-12) * Added referral model instance parameter to `generate_code` callback (`PINAX_REFERRALS_CODE_GENERATOR_CALLBACK` variable) diff --git a/pinax/referrals/tests/tests.py b/pinax/referrals/tests/tests.py index c2eeaa9..d4d505d 100644 --- a/pinax/referrals/tests/tests.py +++ b/pinax/referrals/tests/tests.py @@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model from django.test import TestCase -from pinax.referrals.models import Referral +from pinax.referrals.models import Referral, ReferralResponse class Tests(TestCase): @@ -74,3 +74,24 @@ def test_process_referral_authenticated_next_unsafe(self): self.assertEqual(referral.responses.count(), 1) referral_response = referral.responses.first() self.assertEqual(referral_response.user, referred_user) + + def test_process_referral_slash_both_variants(self): + referral = Referral.create(redirect_to="https://example.com/") + self.assertFalse(referral.responses.exists()) + response = self.client.get(referral.url.rstrip("/")) + self.assertEqual(response.status_code, 302) + self.assertEqual(response["Location"], "https://example.com/") + self.assertEqual(referral.responses.count(), 1) + referral_response = referral.responses.first() + self.assertIsNone(referral_response.user) + self.assertEqual(response.cookies["pinax-referral"].value, f"{referral.code}:{referral_response.session_key}") + + ReferralResponse.objects.all().delete() + + response = self.client.get(referral.url.rstrip("/") + "/") + self.assertEqual(response.status_code, 302) + self.assertEqual(response["Location"], "https://example.com/") + self.assertEqual(referral.responses.count(), 1) + referral_response = referral.responses.first() + self.assertIsNone(referral_response.user) + self.assertEqual(response.cookies["pinax-referral"].value, f"{referral.code}:{referral_response.session_key}") diff --git a/pinax/referrals/urls.py b/pinax/referrals/urls.py index f6787b5..c78385f 100644 --- a/pinax/referrals/urls.py +++ b/pinax/referrals/urls.py @@ -1,4 +1,4 @@ -from django.urls import path +from django.urls import path, re_path from .views import create_referral, process_referral @@ -6,5 +6,5 @@ urlpatterns = [ path("", create_referral, name="create_referral"), - path("", process_referral, name="process_referral") + re_path(r"^(?P[\w-]+)/?$", process_referral, name="process_referral"), ]