Changeset - 890189aa2bfe
[Not reviewed]
stable
0 2 0
Mads Kiilerich - 10 years ago 2016-01-05 16:24:23
madski@unity3d.com
middleware: decode the repo_name received from http header to unicode

The middlewares seemed to make the incorrect assumption that the headers
contained unicode. Or to put it differently: They relied on the Python default
encoding to be able to convert to unicode instead of using safe_unicode. It
would thus fail if running with LANG=C.

Instead, utilize that the header actually contains str_repo_name and explicitly
decode that to unicode.
2 files changed with 12 insertions and 8 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/middleware/simplegit.py
Show inline comments
 
@@ -38,7 +38,7 @@ from webob.exc import HTTPNotFound, HTTP
 
    HTTPNotAcceptable
 
from kallithea.model.db import User, Ui
 

	
 
from kallithea.lib.utils2 import safe_str, fix_PATH, get_server_url,\
 
from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url,\
 
    _set_extras
 
from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback
 
from kallithea.lib.utils import make_ui, is_valid_repo
 
@@ -79,9 +79,11 @@ class SimpleGit(BaseVCSController):
 
        # EXTRACT REPOSITORY NAME FROM ENV
 
        #======================================================================
 
        try:
 
            repo_name = self.__get_repository(environ)
 
            str_repo_name = self.__get_repository(environ)
 
            repo_name = safe_unicode(str_repo_name)
 
            log.debug('Extracted repo name is %s', repo_name)
 
        except Exception:
 
        except Exception as e:
 
            log.error('error extracting repo_name: %r', e)
 
            return HTTPInternalServerError()(environ, start_response)
 

	
 
        # quick check if that dir exists...
 
@@ -176,7 +178,6 @@ class SimpleGit(BaseVCSController):
 
        #===================================================================
 
        # GIT REQUEST HANDLING
 
        #===================================================================
 
        str_repo_name = safe_str(repo_name)
 
        repo_path = os.path.join(safe_str(self.basepath),str_repo_name)
 
        log.debug('Repository path is %s', repo_path)
 

	
kallithea/lib/middleware/simplehg.py
Show inline comments
 
@@ -37,7 +37,7 @@ from webob.exc import HTTPNotFound, HTTP
 
    HTTPNotAcceptable
 
from kallithea.model.db import User
 

	
 
from kallithea.lib.utils2 import safe_str, fix_PATH, get_server_url,\
 
from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url,\
 
    _set_extras
 
from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback
 
from kallithea.lib.utils import make_ui, is_valid_repo, ui_sections
 
@@ -83,9 +83,13 @@ class SimpleHg(BaseVCSController):
 
        # EXTRACT REPOSITORY NAME FROM ENV
 
        #======================================================================
 
        try:
 
            repo_name = environ['REPO_NAME'] = self.__get_repository(environ)
 
            str_repo_name = environ['REPO_NAME'] = self.__get_repository(environ)
 
            assert isinstance(str_repo_name, str)
 
            repo_name = safe_unicode(str_repo_name)
 
            assert safe_str(repo_name) == str_repo_name, (str_repo_name, repo_name)
 
            log.debug('Extracted repo name is %s', repo_name)
 
        except Exception:
 
        except Exception as e:
 
            log.error('error extracting repo_name: %r', e)
 
            return HTTPInternalServerError()(environ, start_response)
 

	
 
        # quick check if that dir exists...
 
@@ -179,7 +183,6 @@ class SimpleHg(BaseVCSController):
 
        #======================================================================
 
        # MERCURIAL REQUEST HANDLING
 
        #======================================================================
 
        str_repo_name = safe_str(repo_name)
 
        repo_path = os.path.join(safe_str(self.basepath), str_repo_name)
 
        log.debug('Repository path is %s', repo_path)
 

	
0 comments (0 inline, 0 general)