Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6102e29

Browse files
committed
fixes bug #111951
applies patch #101369 by Moshe Zadke use explicit list of always safe characters instead of string.letters add test case
1 parent 7e861bd commit 6102e29

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

Lib/test/output/test_urllib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test_urllib

Lib/test/test_urllib.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Minimal test of the quote function
2+
import urllib
3+
4+
chars = 'abcdefghijklmnopqrstuvwxyz'\
5+
'\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356' \
6+
'\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377' \
7+
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \
8+
'\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317' \
9+
'\320\321\322\323\324\325\326\330\331\332\333\334\335\336'
10+
11+
expected = 'abcdefghijklmnopqrstuvwxyz%df%e0%e1%e2%e3%e4%e5%e6%e7%e8%e9%ea%eb%ec%ed%ee%ef%f0%f1%f2%f3%f4%f5%f6%f8%f9%fa%fb%fc%fd%fe%ffABCDEFGHIJKLMNOPQRSTUVWXYZ%c0%c1%c2%c3%c4%c5%c6%c7%c8%c9%ca%cb%cc%cd%ce%cf%d0%d1%d2%d3%d4%d5%d6%d8%d9%da%db%dc%dd%de'
12+
13+
test = urllib.quote(chars)
14+
assert test == expected, "urllib.quote problem"

Lib/urllib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,9 @@ def unquote_plus(s):
10111011
s = string.join(string.split(s, '+'), ' ')
10121012
return unquote(s)
10131013

1014-
always_safe = string.letters + string.digits + '_,.-'
1014+
always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1015+
'abcdefghijklmnopqrstuvwxyz'
1016+
'0123456789' '_,.-')
10151017
def quote(s, safe = '/'):
10161018
"""quote('abc def') -> 'abc%20def'."""
10171019
# XXX Can speed this up an order of magnitude
@@ -1043,7 +1045,6 @@ def urlencode(dict):
10431045
l.append(k + '=' + v)
10441046
return string.join(l, '&')
10451047

1046-
10471048
# Proxy handling
10481049
def getproxies_environment():
10491050
"""Return a dictionary of scheme -> proxy server URL mappings.

0 commit comments

Comments
 (0)