Skip to content

Commit

Permalink
Proactively check for an unencodable data before passing it along.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Mar 29, 2012
1 parent 9448013 commit bb38bf1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions django_website/docs/views.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
from __future__ import absolute_import

import datetime

import django.views.static
from django.core import urlresolvers
from django.http import Http404
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from django.utils import simplejson

import haystack.views

from .forms import DocSearchForm
from .models import DocumentRelease
from .utils import get_doc_root_or_404, get_doc_path_or_404


def index(request):
return redirect(DocumentRelease.objects.default())

def language(request, lang):
return redirect(DocumentRelease.objects.default())

def document(request, lang, version, url):
# If either of these can't be encoded as ascii then later on down the line an
#exception will be emitted by unipath, proactively check for bad data (mostly
# from the Googlebot) so we can give a nice 404 error.
try:
version.encode("ascii")
url.encode("ascii")
except UnicodeEncodeError:
raise Http404
docroot = get_doc_root_or_404(lang, version)
doc_path = get_doc_path_or_404(docroot, url)

Expand Down

0 comments on commit bb38bf1

Please sign in to comment.