Procházet zdrojové kódy

Hutchison/master (#4106)

* Fixes a potential redirect loop in ProductDetailView if URL includes certain characters

If the URL includes a colon ':' then the ProductDetailView is getting
trapped into a redirect loop.

* Added test to prove the point

---------

Co-authored-by: Martin Darmüntzel <martin@trivialanalog.de>
master
Voxin Muyli před 2 roky
rodič
revize
3c0f3adf39
Žádný účet není propojen s e-mailovou adresou tvůrce revize

+ 1
- 1
src/oscar/apps/catalogue/views.py Zobrazit soubor

@@ -67,7 +67,7 @@ class ProductDetailView(DetailView):
67 67
 
68 68
         if self.enforce_paths:
69 69
             expected_path = product.get_absolute_url()
70
-            if expected_path != quote(current_path):
70
+            if quote(expected_path) != quote(current_path):
71 71
                 return HttpResponsePermanentRedirect(expected_path)
72 72
 
73 73
     def get_context_data(self, **kwargs):

+ 25
- 0
tests/_site/specialurls.py Zobrazit soubor

@@ -0,0 +1,25 @@
1
+from django.apps import apps
2
+from django.conf.urls.i18n import i18n_patterns
3
+from django.contrib import admin
4
+from django.contrib.staticfiles.urls import staticfiles_urlpatterns
5
+from django.urls import include, path
6
+
7
+from tests._site.apps.myapp.views import TestView
8
+
9
+admin.autodiscover()
10
+
11
+urlpatterns = [
12
+    path('admin/', admin.site.urls),
13
+    path('app:shop/', include(apps.get_app_config('oscar').urls[0])),
14
+    path('i18n/', include('django.conf.urls.i18n')),
15
+]
16
+
17
+urlpatterns += i18n_patterns(
18
+    path('test/', TestView),
19
+)
20
+
21
+urlpatterns += staticfiles_urlpatterns()
22
+
23
+handler403 = 'oscar.views.handler403'
24
+handler404 = 'oscar.views.handler404'
25
+handler500 = 'oscar.views.handler500'

+ 11
- 0
tests/functional/catalogue/test_catalogue.py Zobrazit soubor

@@ -64,6 +64,17 @@ class TestProductDetailView(WebTestCase):
64 64
 
65 65
         self.assertEqual(response.status_code, http_client.NOT_FOUND)
66 66
 
67
+    def test_does_not_go_into_redirect_loop(self):
68
+        "when a product slug contains a colon, there should be no redirect loop"
69
+        with self.settings(ROOT_URLCONF='tests._site.specialurls'):
70
+            product = create_product(slug="no-redirect", is_public=True)
71
+            kwargs = {'product_slug': "si-redirect", 'pk': product.id}
72
+            url = reverse('catalogue:detail', kwargs=kwargs)
73
+            response = self.app.get(url, expect_errors=True)
74
+            self.assertIsRedirect(response)
75
+            response = self.app.get(response['Location'])
76
+            self.assertIsNotRedirect(response)
77
+
67 78
 
68 79
 class TestProductListView(WebTestCase):
69 80
 

Načítá se…
Zrušit
Uložit