Skip to content

Commit

Permalink
urlquote paths when checking if correct URL was used
Browse files Browse the repository at this point in the history
Otherwise the check fails when using unicode slugs.
  • Loading branch information
maiksprenger committed Mar 20, 2014
1 parent 4268ba0 commit 801464d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions oscar/apps/catalogue/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import warnings
from django.utils.http import urlquote
from django.conf import settings
from django.http import HttpResponsePermanentRedirect
from django.shortcuts import get_object_or_404
from django.views.generic import ListView, DetailView
from oscar.core.loading import get_model
from django.utils.translation import ugettext_lazy as _

from oscar.core.loading import get_class
from oscar.core.loading import get_class, get_model
from oscar.apps.catalogue.signals import product_viewed

Product = get_model('catalogue', 'product')
Expand Down Expand Up @@ -34,9 +34,9 @@ def get(self, request, **kwargs):
return HttpResponsePermanentRedirect(
product.parent.get_absolute_url())

correct_path = product.get_absolute_url()
if correct_path != request.path:
return HttpResponsePermanentRedirect(correct_path)
expected_path = product.get_absolute_url()
if expected_path != urlquote(request.path):
return HttpResponsePermanentRedirect(expected_path)

response = super(ProductDetailView, self).get(request, **kwargs)
self.send_signal(request, response, product)
Expand Down Expand Up @@ -135,11 +135,11 @@ def get_object(self):
def get(self, request, *args, **kwargs):
self.get_object()
if self.enforce_paths and self.category is not None:
# Categories are fetched by primary key to allow slug changes
# If the slug has indeed changed, issue a redirect
correct_path = self.category.get_absolute_url()
if correct_path != request.path:
return HttpResponsePermanentRedirect(correct_path)
# Categories are fetched by primary key to allow slug changes.
# If the slug has indeed changed, issue a redirect.
expected_path = self.category.get_absolute_url()
if expected_path != urlquote(request.path):
return HttpResponsePermanentRedirect(expected_path)
return super(ProductCategoryView, self).get(request, *args, **kwargs)

def get_categories(self):
Expand Down

0 comments on commit 801464d

Please sign in to comment.