Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with route('') #16

Closed
mithrandi opened this issue Sep 22, 2015 · 1 comment
Closed

Issue with route('') #16

mithrandi opened this issue Sep 22, 2015 · 1 comment

Comments

@mithrandi
Copy link
Contributor

The documentation seems to indicate that route('') and route('/') should mean the same thing, and in fact the '' version seems to make more sense to me. However, it doesn't appear to actually work, as this gist demonstrates: https://gist.github.com/mithrandi/d72ff26f86de69cdb40e

You can run this with twistd -n web --class resource.Root. Trying to visit /foo/ results in the following traceback:

2015-09-22 19:03:11+0200 [HTTPChannel,1,127.0.0.1] Unhandled Error
        Traceback (most recent call last):
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/twisted/web/server.py", line 234, in render
            body = resrc.render(self)
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/twisted/web/util.py", line 139, in render
            self.d.addCallback(self._cbChild, request).addErrback(
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 317, in addCallback
            callbackKeywords=kw)
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 306, in addCallbacks
            self._runCallbacks()
        --- <exception caught here> ---
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 588, in _runCallbacks
            current.result = callback(current.result, *args, **kw)
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/twisted/web/util.py", line 145, in _cbChild
            request.render(resource.getChildForRequest(child, request))
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/twisted/web/server.py", line 234, in render
            body = resrc.render(self)
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/txspinneret/resource.py", line 183, in render
            result = self._wrappedResource.render(request)
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/txspinneret/route.py", line 238, in render
            result, segments = self._matchRoute(request, [])
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/txspinneret/route.py", line 229, in _matchRoute
            matches, remaining = route(request, segments)
          File "/home/mithrandi/deployment/virtualenvs/tempenv-2c7834670678/local/lib/python2.7/site-packages/txspinneret/route.py", line 113, in _matchRoute
            if components[0] == '/':
        exceptions.IndexError: string index out of range

Funnily enough, the same happens if you try to visit /foo. Changing the route matcher to route('/') fixes both exceptions (the former returning the expected string, and the latter returning 404, all as expected).

@mithrandi
Copy link
Contributor Author

Edited the gist slightly to demonstrate both working and broken cases at the same time; fetching /working/ should work, and fetching /broken/ produces a traceback like the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant