﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	launchpad_bug
3874	Incorrect encode in allmydata.testing.web._FakeTahoeUriHandler.render_GET	exarkun		"`render_GET` does:

{{{
        for arg, value in uri.query:
            if arg == u""uri"":
                capability = value
        # it's legal to use the form ""/uri/<capability>""                                                                                                                          
        if capability is None and request.postpath and request.postpath[0]:
            capability = request.postpath[0]

        # if we don't yet have a capability, that's an error                                                                                                                      
        if capability is None:
            request.setResponseCode(http.BAD_REQUEST)
            return b""GET /uri requires uri=""

        # the user gave us a capability; if our Grid doesn't have any                                                                                                             
        # data for it, that's an error.                                                                                                                                           
        capability = capability.encode('ascii')
}}}

So it reads `capability` from either a DecodedURL's `query` attribute or from `request.postpath[0]`.  `DecodedURL.query` is certainly a str.

`request.postpath` comes from `twisted.web.server.Request.process`:

{{{
    self.postpath = list(map(unquote, self.path[1:].split(b'/')))
}}}


`self.path` must be `bytes` since it is being split with `bytes` but it comes from `twisted.web.http.Request.requestReceived`:

{{{
        x = self.uri.split(b'?', 1)

        if len(x) == 1:
            self.path = self.uri
        else:
            self.path, argstring = x
            self.args = parse_qs(argstring, 1)
}}}

`requestReceived` also documents `path` as `bytes` and then derives `self.uri` from it so ... probably bytes.

Thus, in Tahoe, `capability` is either str or bytes depending on which codepath finds it.  And if it is bytes then `.encode('ascii')` fails.

which seems to confirm that it is bytes."	defect	closed	normal	undecided	unknown	n/a	fixed			
