[Web-SIG] invalid http.cookiejar test?

Bill Janssen janssen at parc.com
Fri Aug 8 19:26:23 CEST 2008


I'm looking at the following test case in test_http_cookiejar, in the
Python 3000 test suite.  It seems to assume that URLs can have
non-ASCII characters in them, and in fact random octets.  My understanding
of RFC 3986, the URI RFC, is that the URI must be all ASCII characters,
though segments of the path, and parameters, and query elements, can all
contain percent-encoded octets for various purposes.

So I'd expect this test, which to my eyes contains one valid URL (the
first one), and two invalid ones, to fail when it encounters the
invalid URLs, but clearly the intent of whoever wrote this was that it
would succeed.  Which is the correct expectation?

Bill

    def test_url_encoding(self):
        # Try some URL encodings of the PATHs.
        # (the behaviour here has changed from libwww-perl)
        c = CookieJar(DefaultCookiePolicy(rfc2965=True))
        interact_2965(c, "http://www.acme.com/foo%2f%25/%3c%3c%0Anew%E5/%E5",
                      "foo  =   bar; version    =   1")

[no problem so far...]

        cookie = interact_2965(
            c, "http://www.acme.com/foo%2f%25/<<%0anew\345/\346\370\345",
            'bar=baz; path="/foo/"; version=1');

[..."cookie" should be None here, because URL was invalid...]

        version_re = re.compile(r'^\$version=\"?1\"?', re.I)

[...so the following assertion should fail...]

        self.assert_("foo=bar" in cookie and version_re.search(cookie))

        cookie = interact_2965(
            c, "http://www.acme.com/foo/%25/<<%0anew\345/\346\370\345")

[...and this assertion should succeed, because of the invalid URL...]

        self.assert_(not cookie)

        # unicode URL doesn't raise exception

[Um, why shouldn't this next bit raise an exception?]

        cookie = interact_2965(c, "http://www.acme.com/\xfc")



More information about the Web-SIG mailing list