diff --git a/dpaste/tests/test_api.py b/dpaste/tests/test_api.py index a086bd4..063d58e 100644 --- a/dpaste/tests/test_api.py +++ b/dpaste/tests/test_api.py @@ -239,3 +239,13 @@ class SnippetAPITestCase(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(Snippet.objects.count(), 1) self.assertEqual(Snippet.objects.all()[0].lexer, 'php') + + def test_leading_white_is_retained(self): + """ + Leading Whitespace is retained in the db. + """ + content = u' one\n two\n three\n four' + self.client.post(self.api_url, {'content': content}) + self.assertEqual(Snippet.objects.all()[0].content, content) + + diff --git a/dpaste/tests/test_snippet.py b/dpaste/tests/test_snippet.py index 1b2b055..cd598df 100644 --- a/dpaste/tests/test_snippet.py +++ b/dpaste/tests/test_snippet.py @@ -401,3 +401,12 @@ class SnippetTestCase(TestCase): slug_list = Snippet.objects.values_list( 'secret_id', flat=True).order_by('published') self.assertEqual(len(set(slug_list)), 100) + + def test_leading_white_is_retained_in_db(self): + """ + Leading Whitespace is retained in the db. + """ + content = u' one\n two\n three\n four' + data = self.valid_form_data(content=content) + self.client.post(self.new_url, data, follow=True) + self.assertEqual(Snippet.objects.all()[0].content, content) diff --git a/dpaste/views.py b/dpaste/views.py index e6009b0..214d3ec 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -6,15 +6,13 @@ import json from django.conf import settings from django.core.exceptions import ObjectDoesNotExist -from django.urls import reverse from django.db.models import Count from django.http import (Http404, HttpResponse, HttpResponseBadRequest, - HttpResponseRedirect) + HttpResponseRedirect) from django.shortcuts import get_object_or_404 -from django.utils.decorators import method_decorator +from django.urls import reverse from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from django.views.decorators.csrf import csrf_exempt from django.views.defaults import page_not_found as django_page_not_found, \ server_error as django_server_error from django.views.generic import FormView @@ -112,7 +110,6 @@ class SnippetDetailView(SnippetView, DetailView): def highlight_snippet(self): snippet = self.get_object() h = pygmentize(snippet.content, snippet.lexer) - h = h.replace(u' ', u'  ') h = h.replace(u'\t', '    ') return h