Commit 034ec785 authored by Gregory P. Smith's avatar Gregory P. Smith

Merged revisions 83145 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/release27-maint

........
  r83145 | gregory.p.smith | 2010-07-25 12:11:36 -0700 (Sun, 25 Jul 2010) | 3 lines

  Fixes issue #3704: cookielib was not properly handling URLs with a / in the
  parameters.
........
parent 7c973454
...@@ -607,19 +607,14 @@ def eff_request_host(request): ...@@ -607,19 +607,14 @@ def eff_request_host(request):
return req_host, erhn return req_host, erhn
def request_path(request): def request_path(request):
"""request-URI, as defined by RFC 2965.""" """Path component of request-URI, as defined by RFC 2965."""
url = request.get_full_url() url = request.get_full_url()
#scheme, netloc, path, parameters, query, frag = urlparse.urlparse(url) parts = urlparse.urlsplit(url)
#req_path = escape_path("".join(urlparse.urlparse(url)[2:])) path = escape_path(parts.path)
path, parameters, query, frag = urlparse.urlparse(url)[2:] if not path.startswith("/"):
if parameters:
path = "%s;%s" % (path, parameters)
path = escape_path(path)
req_path = urlparse.urlunparse(("", "", path, "", query, frag))
if not req_path.startswith("/"):
# fix bad RFC 2396 absoluteURI # fix bad RFC 2396 absoluteURI
req_path = "/"+req_path path = "/" + path
return req_path return path
def request_port(request): def request_port(request):
host = request.get_host() host = request.get_host()
......
# -*- coding: latin-1 -*- # -*- coding: latin-1 -*-
"""Tests for cookielib.py.""" """Tests for cookielib.py."""
import re, os, time import cookielib
import os
import re
import time
from unittest import TestCase from unittest import TestCase
from test import test_support from test import test_support
class DateTimeTests(TestCase): class DateTimeTests(TestCase):
def test_time2isoz(self): def test_time2isoz(self):
...@@ -563,6 +568,16 @@ class CookieTests(TestCase): ...@@ -563,6 +568,16 @@ class CookieTests(TestCase):
interact_netscape(c, "http://www.acme.com/blah/rhubarb/", 'eggs="bar"') interact_netscape(c, "http://www.acme.com/blah/rhubarb/", 'eggs="bar"')
self.assert_("/blah/rhubarb" in c._cookies["www.acme.com"]) self.assert_("/blah/rhubarb" in c._cookies["www.acme.com"])
def test_default_path_with_query(self):
cj = cookielib.CookieJar()
uri = "http://example.com/?spam/eggs"
value = 'eggs="bar"'
interact_netscape(cj, uri, value)
# default path does not include query, so is "/", not "/?spam"
self.assert_("/" in cj._cookies["example.com"])
# cookie is sent back to the same URI
self.assertEquals(interact_netscape(cj, uri), value)
def test_escape_path(self): def test_escape_path(self):
from cookielib import escape_path from cookielib import escape_path
cases = [ cases = [
...@@ -591,15 +606,14 @@ class CookieTests(TestCase): ...@@ -591,15 +606,14 @@ class CookieTests(TestCase):
from urllib2 import Request from urllib2 import Request
from cookielib import request_path from cookielib import request_path
# with parameters # with parameters
req = Request("http://www.example.com/rheum/rhaponicum;" req = Request("http://www.example.com/rheum/rhaponticum;"
"foo=bar;sing=song?apples=pears&spam=eggs#ni") "foo=bar;sing=song?apples=pears&spam=eggs#ni")
self.assertEquals(request_path(req), "/rheum/rhaponicum;" self.assertEquals(request_path(req),
"foo=bar;sing=song?apples=pears&spam=eggs#ni") "/rheum/rhaponticum;foo=bar;sing=song")
# without parameters # without parameters
req = Request("http://www.example.com/rheum/rhaponicum?" req = Request("http://www.example.com/rheum/rhaponticum?"
"apples=pears&spam=eggs#ni") "apples=pears&spam=eggs#ni")
self.assertEquals(request_path(req), "/rheum/rhaponicum?" self.assertEquals(request_path(req), "/rheum/rhaponticum")
"apples=pears&spam=eggs#ni")
# missing final slash # missing final slash
req = Request("http://www.example.com") req = Request("http://www.example.com")
self.assertEquals(request_path(req), "/") self.assertEquals(request_path(req), "/")
......
...@@ -81,6 +81,9 @@ C-API ...@@ -81,6 +81,9 @@ C-API
Library Library
------- -------
- Issue #3704: cookielib was not properly handling URLs with a / in the
parameters.
- Issue #4629: getopt raises an error if an argument ends with = whereas getopt - Issue #4629: getopt raises an error if an argument ends with = whereas getopt
doesn't except a value (eg. --help= is rejected if getopt uses ['help='] long doesn't except a value (eg. --help= is rejected if getopt uses ['help='] long
options). options).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment