Skip to content

Commit 56a4f44

Browse files
author
Rob Myers
committed
Tackle invalid lang specs before the code sees them.
1 parent e56192c commit 56a4f44

File tree

1 file changed

+12
-0
lines changed
  • python_env/src/cc.engine/cc/engine

1 file changed

+12
-0
lines changed

python_env/src/cc.engine/cc/engine/app.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import sys
23
import urllib
34

@@ -27,11 +28,22 @@ def __init__(self, staticdirector, config):
2728
self.staticdirector = staticdirector
2829
self.config = config
2930

31+
def clean_lang(self, request):
32+
"""Avoid invalid lang specs not of the form aa aa-aa aa-AA aa_aa aa_AA.
33+
If we encounter one, remove it."""
34+
request_form = request.GET or request.POST
35+
if request_form.has_key('lang') and request_form['lang'] != '':
36+
if not re.match(r'^[a-z]{2}([-_][a-zA-Z]{2})?$',
37+
request_form['lang']):
38+
del request_form['lang']
39+
3040
def __call__(self, environ, start_response):
3141
request = Request(environ)
3242
path_info = request.path_info
3343
route_match = routing.mapping.match(path_info)
3444

45+
self.clean_lang(request)
46+
3547
if route_match is None:
3648
# If there's an equivalent URL that ends with /, redirect
3749
# to that.

0 commit comments

Comments
 (0)