Ticket #1291: static_serve_empty_path_compnent.diff

File static_serve_empty_path_compnent.diff, 1.3 KB (added by graham.carlyle@…, 17 years ago)

test to illustrate problem and potential fix

  • django/views/static.py

     
    3333
    3434    # Clean up given path to only allow serving files below document_root.
    3535    path = posixpath.normpath(urllib.unquote(path))
     36    path = path.lstrip('/')
    3637    newpath = ''
    3738    for part in path.split('/'):
    3839        if not part:
  • tests/regressiontests/views/tests/static.py

     
    1212        for filename in media_files:
    1313            response = self.client.get('/views/site_media/%s' % filename)
    1414            file = open(path.join(media_dir, filename))
    15             self.assertEquals(file.read(), response.content)
    16  No newline at end of file
     15            self.assertEquals(file.read(), response.content)
     16
     17    def test_copes_with_empty_path_component(self):
     18        file_name = 'file.txt'
     19        response = self.client.get('/views/site_media//%s' % file_name)
     20        file = open(path.join(media_dir, file_name))
     21        self.assertEquals(file.read(), response.content)
     22       
     23       
Back to Top