Skip to content

Instantly share code, notes, and snippets.

@un33k
Created July 5, 2012 11:56
Show Gist options
  • Save un33k/3053283 to your computer and use it in GitHub Desktop.
Save un33k/3053283 to your computer and use it in GitHub Desktop.
This middleware removes extra back2back slashes from incoming request
from django.http import HttpResponseRedirect
import re
slash_re = re.compile('/{2,}')
class SingleSlashes:
""" This middleware removes extra back2back slashes from an incoming request """
def process_request(self, request):
if '//' in request.path:
new_path = slash_re.sub('/', request.path)
return HttpResponseRedirect(new_path)
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment