← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wallyworld/launchpad/has_matches-opps-querystring into lp:launchpad

 

Ian Booth has proposed merging lp:~wallyworld/launchpad/has_matches-opps-querystring into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #455803 in Launchpad itself: "TraversalError: 'has_matches' OOPS when passing twice a variable in the query"
  https://bugs.launchpad.net/launchpad/+bug/455803

For more details, see:
https://code.launchpad.net/~wallyworld/launchpad/has_matches-opps-querystring/+merge/61095

= Implementation =

Tweak the PackageSearchViewBase class so that if there is more than one text parameter value passed in, only the last one is used.

= Tests =

Enhance lp/soyuz/browser/tests/distribution-views.txt to ensure +search with multiple text values works as expected.

= Lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/soyuz/browser/packagesearch.py
  lib/lp/soyuz/browser/tests/distribution-views.txt

-- 
https://code.launchpad.net/~wallyworld/launchpad/has_matches-opps-querystring/+merge/61095
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wallyworld/launchpad/has_matches-opps-querystring into lp:launchpad.
=== modified file 'lib/lp/soyuz/browser/packagesearch.py'
--- lib/lp/soyuz/browser/packagesearch.py	2011-01-24 17:39:45 +0000
+++ lib/lp/soyuz/browser/packagesearch.py	2011-05-16 11:27:29 +0000
@@ -19,7 +19,14 @@
         """Save the search text set by the user."""
         self.text = self.request.get("text", None)
         if self.text is not None:
+            # The user may have URL hacked a query string with more than one
+            # "text" parameter. We'll take the last one.
+            if isinstance(self.text, list):
+                self.text = self.text[-1]
             self.text = self.text.strip()
+            # We need to ensure the form on the refreshed page shows the
+            # correct text.
+            self.request.form['text'] = self.text
 
     @property
     def search_requested(self):
@@ -44,7 +51,7 @@
     @cachedproperty
     def search_results(self):
         """Search for packages matching the request text.
-        
+
         Try to find the packages that match the given text, then present
         those as a list. Cache previous results so the search is only done
         once.

=== modified file 'lib/lp/soyuz/browser/tests/distribution-views.txt'
--- lib/lp/soyuz/browser/tests/distribution-views.txt	2010-11-12 14:12:15 +0000
+++ lib/lp/soyuz/browser/tests/distribution-views.txt	2011-05-16 11:27:29 +0000
@@ -123,6 +123,14 @@
     >>> distro_pkg_search_view.text
     'a'
 
+If there is more than one text parameter value, the last one is used.
+
+    >>> distro_pkg_search_view = create_initialized_view(
+    ...     ubuntu, name="+search",
+    ...     form={'text': ['a','b']},
+    ...     query_string='text=a&text=b')
+    >>> distro_pkg_search_view.text
+    'b'
 
 Exact matches
 .............