Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 755

Show
Ignore:
Timestamp:
10/27/05 18:06:41
Author:
fumanchu
Message:

Test and fix for #371 (Redirect of index method to trailing-slash URI uses the wrong path info).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cphttptools.py

    r737 r755  
    753753        #   a redirect) 
    754754        if path[-1] != '/': 
    755             newUrl = path + '/' 
    756             if cherrypy.request.queryString: 
    757                 newUrl += "?" + cherrypy.request.queryString 
     755            atoms = cherrypy.request.browserUrl.split("?", 1) 
     756            newUrl = atoms.pop(0) + '/' 
     757            if atoms: 
     758                newUrl += "?" + atoms[0] 
    758759            if getattr(cherrypy, "debug", None): 
    759760                cherrypy.log("    Found: redirecting to %s" % newUrl, "DEBUG") 
  • trunk/cherrypy/test/test_core.py

    r754 r755  
    3838class Root: 
    3939     
     40    _cpFilterList = [] 
     41     
    4042    def index(self): 
    4143        return "hello" 
     
    5052 
    5153class TestType(type): 
    52     """Metaclass which automatically exposes all functions in each subclass.""" 
     54    """Metaclass which automatically exposes all functions in each subclass, 
     55    and adds an instance of the subclass as an attribute of cherrypy.root. 
     56    """ 
    5357    def __init__(cls, name, bases, dct): 
    5458        type.__init__(name, bases, dct) 
     
    134138        else: 
    135139            raise cherrypy.InternalRedirect('/image/getImagesByUser') 
     140 
     141 
     142class Slash(Test): 
     143    def index(self): 
     144        return "slashed!" 
     145 
     146class VPrefix: 
     147    def __init__(self, prefix): 
     148        self.prefix = prefix 
     149    def onStartResource(self): 
     150        path = cherrypy.request.path 
     151        if path.startswith(self.prefix): 
     152            cherrypy.request.objectPath = path[len(self.prefix):] 
     153cherrypy.root._cpFilterList.append(VPrefix("/vpath")) 
    136154 
    137155 
     
    547565        self.assertStatus('303 See Other') 
    548566        self.assertInBody('/errpage') 
     567         
     568        # Trailing slash redirect on a virtualpath child. 
     569        self.getPage("/vpath/slash") 
     570        self.assertStatus('303 See Other') 
     571        self.assertInBody('/vpath/slash/') 
    549572     
    550573    def testCPFilterList(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets