Issue #20138: The wsgiref.application_uri() and wsgiref.request_uri()
functions now conform to PEP 3333 when handle non-ASCII URLs.
This commit is contained in:
commit
61dab6e3fa
|
@ -286,7 +286,7 @@ class UtilityTests(TestCase):
|
||||||
def testAppURIs(self):
|
def testAppURIs(self):
|
||||||
self.checkAppURI("http://127.0.0.1/")
|
self.checkAppURI("http://127.0.0.1/")
|
||||||
self.checkAppURI("http://127.0.0.1/spam", SCRIPT_NAME="/spam")
|
self.checkAppURI("http://127.0.0.1/spam", SCRIPT_NAME="/spam")
|
||||||
self.checkAppURI("http://127.0.0.1/sp%C3%A4m", SCRIPT_NAME="/späm")
|
self.checkAppURI("http://127.0.0.1/sp%E4m", SCRIPT_NAME="/sp\xe4m")
|
||||||
self.checkAppURI("http://spam.example.com:2071/",
|
self.checkAppURI("http://spam.example.com:2071/",
|
||||||
HTTP_HOST="spam.example.com:2071", SERVER_PORT="2071")
|
HTTP_HOST="spam.example.com:2071", SERVER_PORT="2071")
|
||||||
self.checkAppURI("http://spam.example.com/",
|
self.checkAppURI("http://spam.example.com/",
|
||||||
|
@ -300,15 +300,19 @@ class UtilityTests(TestCase):
|
||||||
def testReqURIs(self):
|
def testReqURIs(self):
|
||||||
self.checkReqURI("http://127.0.0.1/")
|
self.checkReqURI("http://127.0.0.1/")
|
||||||
self.checkReqURI("http://127.0.0.1/spam", SCRIPT_NAME="/spam")
|
self.checkReqURI("http://127.0.0.1/spam", SCRIPT_NAME="/spam")
|
||||||
self.checkReqURI("http://127.0.0.1/sp%C3%A4m", SCRIPT_NAME="/späm")
|
self.checkReqURI("http://127.0.0.1/sp%E4m", SCRIPT_NAME="/sp\xe4m")
|
||||||
self.checkReqURI("http://127.0.0.1/spammity/spam",
|
self.checkReqURI("http://127.0.0.1/spammity/spam",
|
||||||
SCRIPT_NAME="/spammity", PATH_INFO="/spam")
|
SCRIPT_NAME="/spammity", PATH_INFO="/spam")
|
||||||
|
self.checkReqURI("http://127.0.0.1/spammity/sp%E4m",
|
||||||
|
SCRIPT_NAME="/spammity", PATH_INFO="/sp\xe4m")
|
||||||
self.checkReqURI("http://127.0.0.1/spammity/spam;ham",
|
self.checkReqURI("http://127.0.0.1/spammity/spam;ham",
|
||||||
SCRIPT_NAME="/spammity", PATH_INFO="/spam;ham")
|
SCRIPT_NAME="/spammity", PATH_INFO="/spam;ham")
|
||||||
self.checkReqURI("http://127.0.0.1/spammity/spam;cookie=1234,5678",
|
self.checkReqURI("http://127.0.0.1/spammity/spam;cookie=1234,5678",
|
||||||
SCRIPT_NAME="/spammity", PATH_INFO="/spam;cookie=1234,5678")
|
SCRIPT_NAME="/spammity", PATH_INFO="/spam;cookie=1234,5678")
|
||||||
self.checkReqURI("http://127.0.0.1/spammity/spam?say=ni",
|
self.checkReqURI("http://127.0.0.1/spammity/spam?say=ni",
|
||||||
SCRIPT_NAME="/spammity", PATH_INFO="/spam",QUERY_STRING="say=ni")
|
SCRIPT_NAME="/spammity", PATH_INFO="/spam",QUERY_STRING="say=ni")
|
||||||
|
self.checkReqURI("http://127.0.0.1/spammity/spam?s%E4y=ni",
|
||||||
|
SCRIPT_NAME="/spammity", PATH_INFO="/spam",QUERY_STRING="s%E4y=ni")
|
||||||
self.checkReqURI("http://127.0.0.1/spammity/spam", 0,
|
self.checkReqURI("http://127.0.0.1/spammity/spam", 0,
|
||||||
SCRIPT_NAME="/spammity", PATH_INFO="/spam",QUERY_STRING="say=ni")
|
SCRIPT_NAME="/spammity", PATH_INFO="/spam",QUERY_STRING="say=ni")
|
||||||
|
|
||||||
|
|
|
@ -57,14 +57,14 @@ def application_uri(environ):
|
||||||
if environ['SERVER_PORT'] != '80':
|
if environ['SERVER_PORT'] != '80':
|
||||||
url += ':' + environ['SERVER_PORT']
|
url += ':' + environ['SERVER_PORT']
|
||||||
|
|
||||||
url += quote(environ.get('SCRIPT_NAME') or '/')
|
url += quote(environ.get('SCRIPT_NAME') or '/', encoding='latin1')
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def request_uri(environ, include_query=True):
|
def request_uri(environ, include_query=True):
|
||||||
"""Return the full request URI, optionally including the query string"""
|
"""Return the full request URI, optionally including the query string"""
|
||||||
url = application_uri(environ)
|
url = application_uri(environ)
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
path_info = quote(environ.get('PATH_INFO',''),safe='/;=,')
|
path_info = quote(environ.get('PATH_INFO',''), safe='/;=,', encoding='latin1')
|
||||||
if not environ.get('SCRIPT_NAME'):
|
if not environ.get('SCRIPT_NAME'):
|
||||||
url += path_info[1:]
|
url += path_info[1:]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -25,6 +25,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #20138: The wsgiref.application_uri() and wsgiref.request_uri()
|
||||||
|
functions now conform to PEP 3333 when handle non-ASCII URLs.
|
||||||
|
|
||||||
- Issue #19097: Raise the correct Exception when cgi.FieldStorage is given an
|
- Issue #19097: Raise the correct Exception when cgi.FieldStorage is given an
|
||||||
Invalid fileobj.
|
Invalid fileobj.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue