Changeset - 3705a2ba1dac
[Not reviewed]
0 1 0
Brett Smith (brett) - 7 years ago 2016-11-03 14:58:23
brett@sfconservancy.org
static: Re-fix path manipulation in index.

* Strip any leading / to treat it as a relative path.
* Append `index.html` before converting to bytes.
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
www/conservancy/static/views.py
Show inline comments
...
 
@@ -33,20 +33,20 @@ def fundgoal_lookup(fundraiser_sought):
 
        return FundraisingGoal.objects.get(fundraiser_code_name=fundraiser_sought)
 
    except FundraisingGoal.DoesNotExist:
 
     # we have no object!  do something
 
        return None
 

	
 
def index(request, *args, **kwargs):
 
    path = request.path
 
    path = request.path.lstrip(u'/')
 
    if path.endswith(u'/'):
 
        path += u'index.html'
 
    try:
 
        path_bytes = path.encode(FILESYSTEM_ENCODING)
 
    except UnicodeEncodeError:
 
        # If the path can't be expressed on the filesystem, it must not exist.
 
        return handler404(request)
 
    if path.endswith(u'/'):
 
        path += u'index.html'
 
    fullpath = os.path.join(STATIC_ROOT, path_bytes)
 
    if not os.path.exists(fullpath):
 
        return handler404(request)
 
    content_type, _ = mimetypes.guess_type(path)
 
    if content_type != 'text/html':
 
        content = open(fullpath)
0 comments (0 inline, 0 general)