From 75d2da797e100442d3573dfa7ae490972cea32d8 Mon Sep 17 00:00:00 2001 From: Stas Rudakou Date: Fri, 16 May 2014 18:56:25 +0300 Subject: [PATCH] [1.7.x] Fixed #22266 - quote PK before redirecting away from add_view (django.contrib.admin) Backport of ebd70d4d00c252d5122c13906da5bddc8de0bce5 from master. --- django/contrib/admin/options.py | 4 ++-- tests/admin_views/tests.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index d8d56fd1d5..86da05a7fa 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -11,7 +11,7 @@ from django.contrib.admin import widgets, helpers from django.contrib.admin import validation from django.contrib.admin.checks import (BaseModelAdminChecks, ModelAdminChecks, InlineModelAdminChecks) -from django.contrib.admin.utils import (unquote, flatten_fieldsets, +from django.contrib.admin.utils import (quote, unquote, flatten_fieldsets, get_deleted_objects, model_format_dict, NestedObjects, lookup_needs_distinct) from django.contrib.admin.templatetags.admin_static import static @@ -1100,7 +1100,7 @@ class ModelAdmin(BaseModelAdmin): if post_url_continue is None: post_url_continue = reverse('admin:%s_%s_change' % (opts.app_label, opts.model_name), - args=(pk_value,), + args=(quote(pk_value),), current_app=self.admin_site.name) post_url_continue = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, post_url_continue) return HttpResponseRedirect(post_url_continue) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index fbea1d49c7..21f1eb818c 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1779,6 +1779,30 @@ class AdminViewStringPrimaryKeyTest(TestCase): args=(quote(self.pk),)) self.assertContains(response, '