chore: update global_search and add test

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
Chinmay D. Pai 2020-03-30 10:46:00 +05:30
parent 063def052e
commit 10e939d012
No known key found for this signature in database
GPG key ID: 75507BE256F40CED
2 changed files with 5 additions and 2 deletions

View file

@ -191,3 +191,6 @@ class TestGlobalSearch(unittest.TestCase):
frappe.db.commit()
results = global_search.web_search('unsubscribe')
self.assertTrue('Unsubscribe' in results[0].content)
results = global_search.web_search(text='manufacturing',
scope="manufacturing\" UNION ALL SELECT 1,2,3,4,doctype from __global_search")
self.assetTrue(results == [])

View file

@ -501,7 +501,7 @@ def web_search(text, scope=None, start=0, limit=20):
WHERE {conditions}
LIMIT %(limit)s OFFSET %(start)s'''
scope_condition = '`route` like "%(scope)s" AND ' if scope else ''
scope_condition = '`route` like %(scope)s AND ' if scope else ''
published_condition = '`published` = 1 AND '
mariadb_conditions = postgres_conditions = ' '.join([published_condition, scope_condition])
@ -514,7 +514,7 @@ def web_search(text, scope=None, start=0, limit=20):
"scope": "".join([scope, "%"]) if scope else '',
"limit": limit,
"start": start,
"text": frappe.db.escape(text)
"text": text
}
result = frappe.db.multisql({