summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-05-17 18:26:01 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-05-17 18:26:01 -0400
commit7470b6962a989431a469b810340657a26ce0743f (patch)
tree1832ded765f3a88391370114e48c7c9a3435d2c7
parent708f75bb0985c1df4c8df02252080776333e3bad (diff)
downloadaskbot-7470b6962a989431a469b810340657a26ce0743f.tar.gz
askbot-7470b6962a989431a469b810340657a26ce0743f.tar.bz2
askbot-7470b6962a989431a469b810340657a26ce0743f.zip
fixed bug where apostrophe in search query caused an exception
-rw-r--r--askbot/models/question.py2
-rw-r--r--askbot/tests/db_api_tests.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/askbot/models/question.py b/askbot/models/question.py
index 6d25d5a6..797d1c84 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -139,7 +139,7 @@ class QuestionQuerySet(models.query.QuerySet):
elif 'postgresql_psycopg2' in askbot.get_database_engine_name():
rank_clause = "ts_rank(question.text_search_vector, to_tsquery(%s))";
search_query = '&'.join(search_query.split())
- extra_params = ("'" + search_query + "'",)
+ extra_params = (search_query,)
extra_kwargs = {
'select': {'relevance': rank_clause},
'where': ['text_search_vector @@ to_tsquery(%s)'],
diff --git a/askbot/tests/db_api_tests.py b/askbot/tests/db_api_tests.py
index 66fb9f9d..6473845f 100644
--- a/askbot/tests/db_api_tests.py
+++ b/askbot/tests/db_api_tests.py
@@ -143,6 +143,14 @@ class DBApiTests(AskbotTestCase):
count = models.Tag.objects.filter(name='one-tag').count()
self.assertEquals(count, 0)
+ def test_search_with_apostrophe_works(self):
+ self.post_question(
+ user = self.user,
+ body_text = "ahahahahahahah database'"
+ )
+ matches = models.Question.objects.get_by_text_query("database'")
+ self.assertTrue(len(matches) == 1)
+
class UserLikeTests(AskbotTestCase):
def setUp(self):
self.create_user()