searchcell: encode and quote q value in search url (#15352)
This commit is contained in:
parent
ffeb370d0f
commit
1709b97f09
|
@ -21,6 +21,7 @@ from django import template
|
|||
from django.http import HttpResponse
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.forms import models as model_forms, Select
|
||||
from django.utils.http import quote
|
||||
|
||||
from combo.utils import requests
|
||||
from combo.data.models import CellBase
|
||||
|
@ -98,7 +99,7 @@ class SearchCell(CellBase):
|
|||
|
||||
query = request.GET.get('q')
|
||||
if query and cell.search_service.get('url'):
|
||||
url = cell.search_service.get('url') % {'q': query}
|
||||
url = cell.search_service.get('url') % {'q': quote(query.encode('utf-8'))}
|
||||
results = requests.get(url, cache_duration=0).json()
|
||||
else:
|
||||
results = {'err': 0, 'data': []}
|
||||
|
|
|
@ -69,6 +69,10 @@ def test_search_cell(app):
|
|||
assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=foo'
|
||||
assert '<li>' not in resp.content
|
||||
|
||||
resp = client.get('/ajax/search/%s/?q=foo%%23bar' % cell.pk, status=200)
|
||||
assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=foo%23bar'
|
||||
assert '<li>' not in resp.content
|
||||
|
||||
response['data'] = [{'url': 'http://test', 'text': 'barbarbar'}]
|
||||
resp = client.get('/ajax/search/%s/?q=foo' % cell.pk, status=200)
|
||||
assert resp.content.count('<li>') == 1
|
||||
|
|
Loading…
Reference in New Issue