Edgewall Software

Ticket #8128: t8128-tracd-unquote-r7943.patch

File t8128-tracd-unquote-r7943.patch, 1.9 KB (added by cboos, 3 years ago)

revised patch adding explicit unquoting

  • trac/web/standalone.py

     
    2323import os 
    2424import sys 
    2525from SocketServer import ThreadingMixIn 
     26import urllib 
    2627 
    2728from trac import __version__ as VERSION 
    2829from trac.util import autoreload, daemon 
     
    7071        return self.application(environ, start_response) 
    7172 
    7273 
     74class FlupMiddleware(object): 
     75 
     76    def __init__(self, application): 
     77        self.application = application 
     78 
     79    def __call__(self, environ, start_response): 
     80        environ['PATH_INFO'] = urllib.unquote(environ.get('PATH_INFO', '')) 
     81        return self.application(environ, start_response) 
     82 
     83 
    7384class TracEnvironMiddleware(object): 
    7485 
    7586    def __init__(self, application, env_parent_dir, env_paths, single_env): 
     
    147158                      dest='protocol', callback=_validate_callback, 
    148159                      callback_args=(('http', 'scgi', 'ajp'),), 
    149160                      help='http|scgi|ajp') 
     161    parser.add_option('-q', '--unquote', action='store_true', 
     162                      dest='unquote', 
     163                      help='unquote PATH_INFO (may be needed when using ajp') 
    150164    parser.add_option('-e', '--env-parent-dir', action='store', 
    151165                      dest='env_parent_dir', metavar='PARENTDIR', 
    152166                      help='parent directory of the project environments') 
     
    236250        def serve(): 
    237251            server_cls = __import__('flup.server.%s' % options.protocol, 
    238252                                    None, None, ['']).WSGIServer 
    239             ret = server_cls(wsgi_app, bindAddress=server_address).run() 
     253            flup_app = wsgi_app 
     254            if options.unquote: 
     255                flup_app = FlupMiddleware(flup_app) 
     256            ret = server_cls(flup_app, bindAddress=server_address).run() 
    240257            sys.exit(ret and 42 or 0) # if SIGHUP exit with status 42 
    241258 
    242259    try: