changeset 10261:5eae671c0b57 stable

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.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Mon, 28 Dec 2009 12:14:26 +0900
parents d58d7441b211
children eb243551cbd8
files mercurial/hgweb/request.py
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 = []