Changeset - 6b1ed75d7ac9
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 2 years ago 2022-03-14 23:59:47
ben@sturm.com.au
Handle UnicodeEncodeErrors from junk URLs.
1 file changed with 6 insertions and 1 deletions:
0 comments (0 inline, 0 general)
www/conservancy/static/views.py
Show inline comments
...
 
@@ -34,7 +34,12 @@ def index(request, *args, **kwargs):
 
    if path.endswith(u'/'):
 
        path += u'index.html'
 
    fullpath = os.path.join(STATIC_ROOT, path)
 
    if not os.path.exists(fullpath):
 
    try:
 
        # Junk URLs in production (Python 3.5) are causing UnicodeEncodeErrors
 
        # here. Can't reproduce in development in Python 3.9 - only Python 2.7.
 
        if not os.path.exists(fullpath):
 
            return handler404(request)
 
    except UnicodeEncodeError:
 
        return handler404(request)
 
    content_type, _ = mimetypes.guess_type(path)
 
    if content_type != 'text/html':
0 comments (0 inline, 0 general)