diff --git a/bin/wsgi/viewvc.wsgi b/bin/wsgi/viewvc.wsgi index be9eab912..244b7fb65 100644 --- a/bin/wsgi/viewvc.wsgi +++ b/bin/wsgi/viewvc.wsgi @@ -34,21 +34,8 @@ else: import sapi import viewvc -def recode_latin1_path(path): - return path.encode('latin-1').decode('utf-8') - def application(environ, start_response): server = sapi.WsgiServer(environ, start_response) - - # PEP 3333 demands that PATH_INFO et al carry only latin-1 strings, - # so multibyte versioned path names arrive munged, with each byte - # being a character. But ViewVC generates it's own URLs from - # Unicode strings, where UTF-8 is used during URI-encoding. So we - # need to reinterpret path-carrying CGI environment variables as - # UTF-8 instead of as latin-1. - environ['PATH_INFO'] = recode_latin1_path(environ['PATH_INFO']) - environ['SCRIPT_NAME'] = recode_latin1_path(environ['SCRIPT_NAME']) - cfg = viewvc.load_config(CONF_PATHNAME, server) viewvc.main(server, cfg) return [] diff --git a/lib/sapi.py b/lib/sapi.py index defaf33d4..a05011113 100644 --- a/lib/sapi.py +++ b/lib/sapi.py @@ -283,8 +283,17 @@ def redirect(self, url): self.start_response(status='301 Moved') self._wsgi_write(redirect_notice(url)) - def getenv(self, name, value=None): - return self._environ.get(name, value) + def getenv(self, name, default_value=None): + value = self._environ.get(name, default_value) + # PEP 3333 demands that PATH_INFO et al carry only latin-1 + # strings, so multibyte versioned path names arrive munged, with + # each byte being a character. But ViewVC generates it's own URLs + # from Unicode strings, where UTF-8 is used during URI-encoding. + # So we need to reinterpret path-carrying CGI environment + # variables as UTF-8 instead of as latin-1. + if name in ['PATH_INFO', 'SCRIPT_NAME']: + value = value.encode('latin-1').decode('utf-8', errors='replace') + return value def params(self): return cgi.parse(environ=self._environ, fp=self._environ["wsgi.input"])