From 21f3b454b31fd18ab8e33e209d494af0313ff88a Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 29 Jun 2015 20:31:16 +0200 Subject: [PATCH] Fix bug 1175474 - Correctly compare generated URLs with config values. --- kuma/wiki/tests/test_views.py | 26 ++++++++++++++++++++++++++ kuma/wiki/views.py | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/kuma/wiki/tests/test_views.py b/kuma/wiki/tests/test_views.py index 881afa562be..568139f33b9 100644 --- a/kuma/wiki/tests/test_views.py +++ b/kuma/wiki/tests/test_views.py @@ -335,6 +335,32 @@ def test_revision_view_bleached_content(self): ok_('' not in ct) ok_('Hahaha' in ct) + def test_raw_css_view(self): + """The raw source for a document can be requested""" + self.client.login(username='admin', password='testpass') + doc = document(title='Template:CustomSampleCSS', + slug='Template:CustomSampleCSS', + save=True) + revision( + save=True, + is_approved=True, + document=doc, + content=""" + /* CSS here */ + + body { + padding: 0; + margin: 0; + } + + svg:not(:root) { + display:block; + } + """) + response = self.client.get('%s?raw=true' % + reverse('wiki.document', args=[doc.slug])) + ok_('text/css' in response['Content-Type']) + class PermissionTests(UserTestCase, WikiTestCase): localizing_client = True diff --git a/kuma/wiki/views.py b/kuma/wiki/views.py index ff2aeb9460a..1c8045c85de 100644 --- a/kuma/wiki/views.py +++ b/kuma/wiki/views.py @@ -25,6 +25,7 @@ from django.http.multipartparser import MultiPartParser from django.shortcuts import (get_object_or_404, get_list_or_404, redirect, render) +from django.utils.http import urlunquote_plus from django.utils.safestring import mark_safe from django.views.decorators.http import (require_GET, require_POST, require_http_methods, condition) @@ -402,7 +403,7 @@ def _document_raw(request, doc, doc_html, rendering_params): response = HttpResponse(doc_html) response['X-Frame-Options'] = 'Allow' response['X-Robots-Tag'] = 'noindex' - absolute_url = doc.get_absolute_url() + absolute_url = urlunquote_plus(doc.get_absolute_url()) if absolute_url in (config.KUMA_CUSTOM_CSS_PATH, config.KUMA_CUSTOM_SAMPLE_CSS_PATH):