hgweb: request: strip() form values stable
authorNicolas Dumazet <nicdumz.commits@gmail.com>
Mon, 28 Dec 2009 12:14:26 +0900
branchstable
changeset 10261 5eae671c0b57
parent 10258 d58d7441b211
child 10262 eb243551cbd8
hgweb: request: strip() form values Entering "<correct_cset_hash> " in the search form was not returning anything. This happens relatively often, due to HTML formatting: when copy/pasting a cset hash from the web, selection might contain surrounding spaces.
mercurial/hgweb/request.py
--- a/mercurial/hgweb/request.py	Mon Jan 18 15:37:45 2010 -0200
+++ b/mercurial/hgweb/request.py	Mon Dec 28 12:14:26 2009 +0900
@@ -25,7 +25,8 @@
     'static': [('cmd', ['static']), ('file', None)]
 }
 
-def expand(form):
+def normalize(form):
+    # first expand the shortcuts
     for k in shortcuts.iterkeys():
         if k in form:
             for name, value in shortcuts[k]:
@@ -33,6 +34,9 @@
                     value = form[k]
                 form[name] = value
             del form[k]
+    # And strip the values
+    for k, v in form.iteritems():
+        form[k] = [i.strip() for i in v]
     return form
 
 class wsgirequest(object):
@@ -47,7 +51,9 @@
         self.multiprocess = wsgienv['wsgi.multiprocess']
         self.run_once = wsgienv['wsgi.run_once']
         self.env = wsgienv
-        self.form = expand(cgi.parse(self.inp, self.env, keep_blank_values=1))
+        self.form = normalize(cgi.parse(self.inp,
+                                        self.env,
+                                        keep_blank_values=1))
         self._start_response = start_response
         self.server_write = None
         self.headers = []