[PATCH saem] [search] Strip query before storing it in form['highlight']

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Oct 5 11:00:33 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1505220123 -7200
#      Tue Sep 12 14:42:03 2017 +0200
# Node ID dceca66da16ecdd0d891f3aeaddde08c02b485a7
# Parent  456cecf20e93845ee5bdcdf38b1df51a8cb6f17c
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r dceca66da16e
[search] Strip query before storing it in form['highlight']

Else it may not work expectedly with leading/trailing spaces

diff --git a/cubicweb_saem_ref/views/search.py b/cubicweb_saem_ref/views/search.py
--- a/cubicweb_saem_ref/views/search.py
+++ b/cubicweb_saem_ref/views/search.py
@@ -41,11 +41,11 @@ def highlight_keywords(cw):
 
 class FullTextTranslator(magicsearch.FullTextTranslator):
     """Full text translator adding a 'highlight' element to _cw.form"""
 
     def preprocess_query(self, uquery):
-        self._cw.form['highlight'] = uquery
+        self._cw.form['highlight'] = uquery.strip()
         return super(FullTextTranslator, self).preprocess_query(uquery)
 
 
 class TextSearchResultView(baseviews.TextSearchResultView):
     """Overloaded so that it adds a 'highlight' keyword to the entities URL"""


More information about the saem-devel mailing list