File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import os
99import cgi
1010
11- from urllib import unquote
11+ from urllib import unquote_plus
1212
1313
1414class FieldStorage (cgi .FieldStorage ):
@@ -114,10 +114,10 @@ def add_qs(self, qs):
114114 nv .append ('' )
115115 else :
116116 continue
117- if len ( nv [1 ]) or keep_blank_values :
118- name = unquote (nv [0 ]. replace ( '+' , ' ' ) )
117+ if nv [1 ] or keep_blank_values :
118+ name = unquote_plus (nv [0 ])
119119 if name not in existing_names :
120120 # Only append values that aren't already the FieldStorage;
121121 # this makes POSTed vars override vars on the query string.
122- value = unquote (nv [1 ]. replace ( '+' , ' ' ) )
122+ value = unquote_plus (nv [1 ])
123123 append (cgi .MiniFieldStorage (name , value ))
Original file line number Diff line number Diff line change @@ -43,6 +43,14 @@ def testPostRequestWithBody(self):
4343 self .assertEqual (fs .getlist ('e' ), ['5' , '6' ])
4444 self .assertEqual (fs .getlist ('f' ), ['6' ])
4545
46+ def testPostRequestWithSpacesInValues (self ):
47+ fs = FieldStorage (fp = StringIO (), environ = dict (
48+ REQUEST_METHOD = 'POST' , QUERY_STRING = 'a=b%20c+d' ))
49+ self .assertEqual (fs .getfirst ('a' ), 'b c d' )
50+ fs = FieldStorage (fp = StringIO ('a=b%20c+d' ), environ = dict (
51+ REQUEST_METHOD = 'POST' ))
52+ self .assertEqual (fs .getfirst ('a' ), 'b c d' )
53+
4654 def testPostRequestOverrides (self ):
4755 fs = FieldStorage (
4856 fp = StringIO ('b=8&c=9&d=4&e=5&e=6&f=6' ), environ = dict (
You can’t perform that action at this time.
0 commit comments